You can use the APP_INITIALIZER token to provide your authFactory:
//main entry point import {bootstrap} from '@angular/platform-browser-dynamic'; import {Http,HTTP_PROVIDERS} from '@angular/http'; import {App} from './app'; import {AuthService} from './auth.service'; import {provide, enableProdMode, APP_INITIALIZER} from '@angular/core'; export function authFactory(auth: AuthService){ return auth.login() } bootstrap(App, [ HTTP_PROVIDERS, { provide: APP_INITIALIZER, useFactory: (auth), deps: [AuthService], multi: true } ]).catch(err => console.error(err));
source share