I would like to have an angular5 feature module in a separate library.
I've created a project and put the module declaration inside:
@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.');
}
}
}
After compiling it with tsc
, it turns out that compiling the main project with ng build --prod
gives:
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'ApiModule' was called.