我想在一个单独的库中有一个 angular5 功能模块。
我创建了一个项目并将模块声明放入:
@NgModule({
imports: [],
declarations: [],
exports: [],
providers: []
})
export class ApiModule {
public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders {
return {
ngModule: ApiModule,
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
}
}
constructor( @Optional() @SkipSelf() parentModule: ApiModule) {
if (parentModule) {
throw new Error('ApiModule is already loaded. Import your base AppModule only.');
}
}
}
用 编译后tsc
,结果是用 编译主项目ng build --prod
给出:
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'ApiModule' was called.