【发布时间】:2021-07-28 13:22:59
【问题描述】:
我在 Angular 11 项目中有 AppModule。
@NgModule({
declarations: [
AppComponent,
HomeComponent,
ProfileComponent
],
imports: [
BrowserModule,
AppRoutingModule,
MsalModule.forRoot( new PublicClientApplication({
auth: {
clientId: 'Enter_the_Application_Id_here',
authority: 'Enter_the_Cloud_Instance_Id_Here'
redirectUri: 'Enter_the_Redirect_Uri_Here'
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: isIE, // Set to true for Internet Explorer 11
}
}), null, null)
],
providers: [MyAppConfig,
{
provide: APP_INITITALIZER,
useFactory: getMyUseFactory,
deps: [MyAppConfig],
multi: true
}],
bootstrap: [AppComponent]
})
export class AppModule { }
export function getMyUseFactory(c: MyAppConfig) {
return () => c.load();
}
MyAppConfig中的方法load可以返回json值,例如:
{
clientId: '12345',
env: 'dev'
}
或
{
clientId: '67890',
env: 'qa'
}
在管道自动化 CI/CD 中构建代码时设置环境。现在我想把 clientId 放到下面而不是硬编码。
MsalModule.forRoot( new PublicClientApplication({
auth: {
clientId: 'Enter_the_Application_Id_here',
所以我的问题是如何将useFactory 的返回值应用到clientId?
【问题讨论】:
-
你可以试试这个问题的解决方案:stackoverflow.com/questions/55120488/…
标签: angular typescript