I wrote an angular library with some services to use this in different angular applications. Everything works fine without --prod, so without AOT compile, in the angular application.
Generating the library with ng-packagr as well as with the cli as well as with some different yeoman generators produces everytime the same error. Besides I tried different ng-versions (5.x.x, 6.x.x & 7.x.x). But in all cases everytime (with AOT) the same error when I call LoggerModule.forRoot() in the app.module of the application:
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'LoggerModule' was called.
I read many articles about this topic, tried different angularCompilerOptions in tsconfig. Any further ideas out there? The module works fine without AOT (but this is no option for us)...
NgModule of the library:
@NgModule({
declarations: [],
imports: [],
providers: []
})
export class LoggerModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: LoggerModule,
providers: [LoggerService]
}
}
}
NgModule of the application:
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
LoggerModule.forRoot()
],
providers: [],
bootstrap: [AppComponent],
entryComponents: [AppComponent]
})
export class AppModule {
}
Declare your forRoot outside of your module definition:
import { ModuleWithProviders } from ‘@angular/core’;
export const forRoot: ModuleWithProviders = LoggerModule.forRoot();
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
forRoot
],
providers: [],
bootstrap: [AppComponent],
entryComponents: [AppComponent]
})
export class AppModule {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With