JV3*_*JV3 5 typescript angular angular-aot
我写了一个带有一些服务的角度库,可以在不同的角度应用中使用它.没有--prod,所以没有AOT编译,在角度应用程序中一切正常.
使用ng-packagr以及cli以及一些不同的yeoman生成器生成库每次都会产生相同的错误.此外,我尝试了不同的ng版本(5.xx,6.xx和7.xx).但是在所有情况下,当我在应用程序的app.module中调用LoggerModule.forRoot()时,每次(使用AOT)都会出现相同的错误:
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'LoggerModule' was called.
Run Code Online (Sandbox Code Playgroud)
我阅读了很多关于这个主题的文章,在tsconfig中尝试了不同的angularCompilerOptions.有什么进一步的想法吗?该模块在没有AOT的情况下工作正常(但这不是我们的选择)......
图书馆的NgModule:
@NgModule({
declarations: [],
imports: [],
providers: []
})
export class LoggerModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: LoggerModule,
providers: [LoggerService]
}
}
}
Run Code Online (Sandbox Code Playgroud)
NgModule的应用:
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
LoggerModule.forRoot()
],
providers: [],
bootstrap: [AppComponent],
entryComponents: [AppComponent]
})
export class AppModule {
}
Run Code Online (Sandbox Code Playgroud)
在模块定义之外声明您的 forRoot:
\n\nimport { ModuleWithProviders } from \xe2\x80\x98@angular/core\xe2\x80\x99;\nexport const forRoot: ModuleWithProviders = LoggerModule.forRoot();\n\n@NgModule({\n declarations: [\n AppComponent\n ],\n imports: [\n BrowserModule,\n AppRoutingModule,\n forRoot\n ],\n providers: [],\n bootstrap: [AppComponent],\n entryComponents: [AppComponent]\n})\nexport class AppModule {\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
302 次 |
| 最近记录: |