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

How to solve No 'Access-Control-Allow-Origin' header is present on the requested resource with angular 2 service written with angular-cli?
Usage of watch parameter in eject command of Angular CLI
Serving and testing a bundle after ng build
routerLink stopped working in #angular/cli
How to run Angularcli project with https
what is npm i bootstrap#next?
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?

Categories

HOME
makefile
pug
signalr
windows-7
paramiko
translation
agile
chaiscript
value
avl-tree
deeplearning4j
octopus-deploy
eclipse-cdt
xul
informatica-powercenter
uiview
react-leaflet
lenskit
sendkeys
rhapsody
thumbnails
scalaz7
url.action
apply
hhvm
servicemix
binutils
fabric
thinking-sphinx
bxslider
edb
qtablewidget
remote-server
nunit-3.0
oscommerce
jboss-esb
wcf-security
ical-dotnet
excel-interop
powermta
finite-element-analysis
apiary
worker
openweathermap
sapui
maintenance
android-bitmap
instruction-set
nuget-server
heroku-postgres
iphone-developer-program
createobject
barcode-printing
master
cfeclipse
git-annex
spoofing
nofollow
metalsmith
squirrel
emokit
gemini
mpeg-4
twgl.js
spservices
jericho-html-parser
integral
gulp-livereload
callstack
robocode
jython-2.7
valence
baucis
cling
onselect
haskell-platform
vmware-server
ienumerator
backbone-relational
ng-pattern
justgage
lame
google-closure-library
adomd.net
zend-lucene
snapjs
trailing-slash
mvccontrib
returnurl
cadisplaylink
fotoware
makefile-project
flexicious
nssavepanel
easygui
posting
dcpu-16
adsl
mvccontrib-grid
asp.net-routing
web-analytics-tools
cots

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