angular-cli


How to pass config data to NgModule so NgModule will be compiled with AOT


I have a client Angular2 app which will be consuming a 3rd party NgModule app requiring config data. I need to make config values available as a static property of a service that gets called within different areas of the 3rd party NgModule.
Client app's App.Module:
export const MediaConfig: MediaConfigInterface =
{
MediaUrlRoot: "XXXXXXXXXXXXXXXXXXXXXX",
Key: "YYYYYYYYYYYYYYYY"
};
//app.module.ts
import { MediaModule } from '....';
import { MediaConfig } from './configs';
#NgModule(
{
imports:
[
...
//3rd PARTY
MediaModule.forRoot(MediaConfig),
...
],
declarations:[...],
providers:[...],
bootstrap:[...]
})
export class AppModule { }
3rd party NgModule being imported into client App:
export const CONFIG_DATA = new OpaqueToken('Config Data');
export function configHelperFactory(config: MediaConfigInterface)
{
ClientConfigService.ConfigModel = config;
return ClientConfigService;
}
#NgModule({
imports:[...],
declarations:[...],
exports:[...],
entryComponents:[...],
providers:[]
})
export class MediaModule
{
static forRoot(config: MediaConfigInterface): ModuleWithProviders
{
return {
ngModule: MediaModule,
providers:
[
ClientConfigService,
{
provide: CONFIG_DATA,
useValue: config
},
{
provide: ClientConfigService,
useFactory: configHelperFactory,
deps: [CONFIG_DATA]
}
]
};
}
}
3rd party NgModules static service containing config data from client app:
import { MediaConfigInterface} from "../models";
export class ClientConfigService
{
static ConfigModel: MediaConfigInterface;
static BuildMediaUrl(id: string) : string
{
return '';
};
}
This approach only works if I import ClientConfigService in any component constructor in the client app (I'm currently importing it in app.component.ts). Importing it in the constructor causes the configHelperFactory in 3rd party NgModule to fire which sets the static property with config data.
This approach works and the client app builds with AOT. The problem is it's a bit of a kludge to set config data in App.Module AND import ClientConfigService in any given component's constructor so the configHelperFactory fires.
Is there a way to pass config data into 3rd party NgModule, populate static service property with config data, and be able to build client app with AOT?

Related Links

Angular-Cli Best way to manage notices
Puzzling angular-cli AOT error
Create Project with Angular 4 Release using angularcli
addons removed in angular-cli.json whats the replacement
angular-cli: ng serve command with config error
Augury Angular-cli When I installed the augury .Error is as follows
Teamcity for building Angular cli app
angular cli update issue on local folder
Access to -aot parameter in code
Missing peer dependencies after installing latest angular-cli: What to do?
angular-cli ng serve : Error: No errors
Getting error after Angular cli update
Does angular-cli uses rollup to do ahead-of-time compilation and adding all into one file?
Angular CLI install error
Using glob for assets in angular-cli throws error
Importing Global SCSS into Component SCSS with Angular-CLI

Categories

HOME
symfony
numpy
pug
payment-gateway
voip
wxwidgets
label
command
tumblr
sudo
ipfs
outlook-web-addins
google-shopping
eclipse-luna
primes
propel2
aws-cognito
distance
thingsboard
yosys
badge
branch
rhandsontable
ab-initio
xilinx-ise
reactiveui
ifstream
recurrence-relation
powershell-remoting
redhat-datavirt
knockout-3.0
median
ivona
catia
lirc
mbaas
ruby-on-rails-2
teiid
createobject
windows-azure-pack
xib
activeweb
windows-nt
com-interop
ng2-material
project-online
mpeg-4
inet
post-processing
function-fitting
coldfusion-7
mirrorlink
datasnap
matcaffe
gray-code
callstack
custom-url
jcr-sql2
java-melody
tilestache
activity-streams
tcpreplay
errorprovider
code-testing
voldemort
opensocial
anjuta
ksoap2
arangodb-php
angulartics
haskell-platform
threadx
apache2.2
objcmongodb
template-haskell
abnf
domain-calculus
lync-server-2010
code-conversion
git-filter-branch
getusermedia
pivotal-crm
svn-hooks
hadoop-plugins
plinq
evb
dotproject

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App