1

我想在一个单独的库中有一个 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.
4

1 回答 1

0

问题是tsc不要发出包含来自 Angular 所需的装饰器的所有数据的元数据。

我通过使用ng-packagr https://github.com/dherges/ng-packagr (v2.0.0-rc.11)解决了这个问题

于 2018-01-22T18:51:01.213 回答