Pass config data using forRoot

You are almost there, simply provide both SampleService and config in your module like below: export class SampleModule { static forRoot(config: CustomConfig): ModuleWithProviders<SampleModule> { // User config get logged here console.log(config); return { ngModule: SampleModule, providers: [SampleService, {provide: ‘config’, useValue: config}] }; } } @Injectable() export class SampleService { foo: string; constructor(@Inject(‘config’) private config:CustomConfig) { … Read more

Property ‘X’ is private and only accessible within class ‘xyzComponent’

For a given component all its members (methods, properties) accessed by its template must be public in the AOT compilation scenario. This is due to the fact that a template is turned into a TS class. A generated class and a component are 2 separate classes now and you can’t access private members cross-class. In … Read more