We have a forRoot in which we conditionally build up a providers array based on conditions in a config object. AOT doesn't like this and returns the error 'function calls are not supported in decorators but 'XxxModule' was called'.
forRoot(config: MyModuleOptions){
const providers = [
AService,
BService
];
// here we check some config options to define which other things we inject
if(config.behaviorC){
providers.push(CService);
}
return {
ngModule: MyModule,
providers: providers
};
}
How can we fix this or use another approach to avoid the AOT error?