Is it possible to make the following code AoT-compatible?
interface Config {
someField?: string;
anotherField?: number;
}
@NgModule({})
export class SomeModule {
protected static _config: Config;
public static withConfig(config: Config = {}): ModuleWithProviders {
// the line below fails AoT compilation
SomeModule._config = Object.assign({}, { someField: 'defaultValue' }, config);
return {
ngModule: SomeModule,
providers: []
};
}
}
SomeModule.withConfig()
has to be imported in main module and config has to be set synchronously before the app starts (for decorating function), but with AoT compilation it throws:
Angular compilation done, starting webpack bundling.
Error: Error encountered resolving symbol values statically. Calling function 'SomeModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /.../app/app.module.ts, resolving symbol AppModule in /../app/app.module.ts
Any ideas?
EDIT: because of the comments, here is how I import the module in app.module:
@NgModule({
imports: [
SomeModule.withConfig(), // yeah, just like that or with { someField: '' }
]
})
export class AppModule {}