我想在一个单独的库中安装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.
答案 0 :(得分:0)
问题是tsc
不会发出包含angular所需装饰器的所有数据的元数据。
我使用ng-packagr
https://github.com/dherges/ng-packagr(v2.0.0-rc.11)解决了这个问题