Я пытаюсь динамически загрузить файл конфигурации MSAL, но я получил ошибку:
NullInjectorError: Нет поставщика для InjectionToken MSAL_CONFIG!
Вот код :
import { NgModule, Optional, SkipSelf, APP_INITIALIZER } from "@angular/core";
import { CommonModule } from "@angular/common";
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
import { MsalModule, MsalInterceptor, MsalConfig, MsalService } from "@azure/msal-angular";
import { ConfigService } from "./config/config.service";
import { MSAL_CONFIG } from "@azure/msal-angular/dist/msal.service";
export function initConfiguration(configService: ConfigService) {
// This will load the json file and store it in a variable
return () => configService.init();
}
export function msalConfigFactory(configService: ConfigService): MsalConfig {
// get the config from the service
return configService.get();
}
@NgModule({
imports: [CommonModule, HttpClientModule, MsalModule],
declarations: [],
providers: [
ConfigService,
{
provide: APP_INITIALIZER,
useFactory: initConfiguration,
deps: [ConfigService],
multi: true
},
{
provide: MSAL_CONFIG,
useFactory: msalConfigFactory,
deps: [ConfigService]
},
MsalService,
{
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
}
]
})
export class CoreModule {
constructor(
@Optional()
@SkipSelf()
parentModule: CoreModule
) {
if (parentModule) {
throw new Error("CoreModule is already loaded. Import only in AppModule");
}
}
}
Поскольку я предоставляю объект MSAL_CONFIG, я не понимаю, почему он выдает эту ошибку.
Я попытался переместить все в app.module
, но получил та же ошибка. Что мне здесь не хватает?