I'm trying to get my Angular CLI (1.0.0-rc.1) app to build for produciton and am getting an AOT error. I actually have 2 apps: primary app and a npm installed app for some UI widgets. The UI widgets app requires some configuration data (paths,keys,etc).
Here's my code in my primary app that assembles the config data and passes it to UI Widget module:
export const config: ConfigData =
{
UrlRoot: 'XXXX',
Key: 'ZZZZ'
}
@NgModule({
imports:
[
UiWidgetModule.forRoot(config)
],
declarations:
[],
exports:
[]
})
export class CoreModule
{
static forRoot(): ModuleWithProviders
{
return {
ngModule: CoreModule,
providers:
[]
};
}
}
and here's the UIWidgetModule:
export function configHelperFactory(config: ConfigData)
{
ClientConfigService.ConfigModel = config;
return ClientConfigService;
}
@NgModule({
imports:
[
CommonModule
],
declarations:
[
//COMPONENTS
],
exports:
[
//COMPONENTS
],
entryComponents:
[
//COMPONENTS
],
providers:
[
]
})
export class UiWidgetModule
{
static forRoot(config: ConfigData): ModuleWithProviders
{
return {
ngModule: UiWidgetModule,
providers:
[
ClientConfigService,
{
provide: ClientConfigService,
useFactory: configHelperFactory(config)
}
]
};
}
}
My UIWidgetModule uses a service (ClientConfigService) to hold the configuration data from client. Subsequent components use various functions in ClientConfigService to consume the config data. The kicker is ClientConfigService is static.
Here's ClientConfigService :
import { ConfigData } from "../models/index";
export class ClientConfigService
{
static ConfigModel: ConfigData ;
static BuildMediaUrl(nodeId: string) : string
{
return ClientConfigService.ConfigModel.UrlRoot+ '/' + nodeId;
};
static GetKey(): string
{
return ClientConfigService.ConfigModel.Key;
};
}
The build process for production (AOT) fails miserably trying to set the config value for the static variable of ClientConfigService. How do I consume the config data in my widget module? I love having a static service supply the data so I do not have to drop ClientConfigService in the constructor of every component needing it.
Thanks.