Project becomes inactive after tapping into App_Initializer

16 views
Skip to first unread message

NANA DARKO

unread,
Jun 14, 2019, 6:37:34 AM6/14/19
to Angular and AngularJS discussion
I am getting endpoints from a file within my assets folder before the angular app is bootstrapped. I get the endpoints alright but the app UI doesn't display unless I reresh the page.  The application works fine if I do not tap into App_Initializer. Please I would need your help to fix it. Below is my code

*AppModule
export function init_app(appLoaderService: AppLoaderService) {
return (): Promise<any> => {
return appLoaderService.getEndpoints();
}
}

@NgModule({
providers: [
AppLoaderService,
{
provide: APP_INITIALIZER,
useFactory: init_app,
deps: [AppLoaderService],
multi: true
}
],


*Service
getEndpoints(): Promise<any> {
const promise = this.client.get<EndPoints>('assets/apiEndPoints.json').toPromise()
.then(data => {
this.endpoints = data;
console.log('Endpoints', data);
return data;
});
return promise;
}



Reply all
Reply to author
Forward
0 new messages