【发布时间】:2020-09-08 02:13:28
【问题描述】:
我想创建一个库以便能够在多个应用程序中使用它。该库将是一个允许您使用门户进行连接的模块。我想设置配置以从应用程序创建此模块,配置必须能够覆盖路由来源(例如:'authentification' 可以被'auth'覆盖)。所以我写了这个模块:
{ path: 'authentification', component: StyleRootComponent, children: [
{
path: 'portail',
component: PortailComponent
},
{
path: 'passwordForgotten',
component: PasswordForgotenComponent
}
]
}
];
@NgModule({
declarations: [StyleRootComponent, PortailComponent, PasswordForgotenComponent],
imports: [
RouterModule.forChild(appRoutes),
AmplifyAngularModule,
FormsModule,
MatFormFieldModule,
MatInputModule,
MatCardModule,
BrowserAnimationsModule,
MatButtonModule
],
exports: [StyleRootComponent]
})
export class LibraryConnectionModule {
static forRoot(config: any): ModuleWithProviders {
appRoutes[0].path = config.urlAuth;
return {
ngModule: LibraryConnectionModule,
providers: [
AmplifyService,
AuthentificationService,
{
provide: CognitoConfigsService,
useValue: config.cognitoConfigs
}
]
}
}
}
我可以从应用程序中导入它
imports: [...,
LibraryConnectionModule.forRoot({cognitoConfigs : {}, urlAuth : "auth"}),
...,
]
JIT 的所有工作都像预期的那样,但是当我尝试为生产 (AOT) 构建时,我收到了这个错误:
“AppModule”模板编译期间出现错误
装饰器不支持函数调用,但调用了“LibraryConnectionModule”。
我知道问题出在这条线上(我真的不知道为什么):appRoutes[0].path = config.urlAuth;
所以在生产中我无法从应用程序中选择我的组件的 url...
有人知道我该怎么做吗? (我愿意接受任何建议)
提前致谢 最大
【问题讨论】:
标签: angular configuration angular-library