Angularjs2 – preload server configuration before the application starts [duplicate]

Provide this in your root module

{provide: APP_INITIALIZER, useValue: () => promise, multi: true}]}

where () => promise is some call that returns a Promise that resolves to the desired value.

See also How to pass parameters rendered from backend to angular2 bootstrap method

You can pass a service as dependency where you can store the result.

update

export function loadConfig(config: ConfigService) => () => config.load()

@NgModule({
        declarations: [AppComponent],
        imports: [BrowserModule,
            routes,
            FormsModule,
            HttpModule],
        providers: [AuthService,
            Title,
            appRoutingProviders,
            ConfigService,
            { provide: APP_INITIALIZER,
              useFactory: loadConfig,
              deps: [ConfigService], 
              multi: true }
        ],
        bootstrap: [AppComponent]
    })
    export class AppModule { }

update 2

Plunker example

Leave a Comment