I preload the application configuration from the server APP_INITIALIZERas follows AppModule:
providers: [
ConfigService,
{
provide: APP_INITIALIZER,
useFactory: configServiceFactory,
deps: [ConfigService],
multi: true
}
],
It ApiServiceis then entered manually from ConfigService:
@Injectable()
export class ConfigService {
private api: ApiService;
public constructor(
private injector: Injector
) {
this.api = injector.get(ApiService);
}
And finally, routerthere is undefined when introduced inApiService
import { Http, Headers, RequestOptionsArgs, Response } from '@angular/http';
import { Router } from '@angular/router';
@Injectable()
export class ApiService {
constructor(
private router: Router,
private http: Http
) {
console.log(router, 'router');
debugger;

Here is the plunker
Any thoughts on how this could be fixed / processed?
source
share