Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - How do I delay initial load until service completes?

I have an angular2 RC6 application and I need to defer loading pages until after some functionality is executed.

I have a service that determines the URI for the webApi. I need the application to wait until this URL is determined before it tries to load any data. If I hide the main application in app.component, with an *ngIf, I get routing errors because the router outlet does not exists.

Before RC5/6 I manually bootstrapped the application after the service get's the URI.

like image 336
Don Chambers Avatar asked Oct 19 '22 02:10

Don Chambers


1 Answers

If you use the router you can use canActivate, canActivateChild.

See also

  • https://angular.io/docs/ts/latest/guide/router.html#!#guards
  • Resolve a value *before* activating a route in Angular 2
  • Angular2 canActivate() calling async function

For loading once before app initialization you can use APP_INITIALIZER as explained in How to pass parameters rendered from backend to angular2 bootstrap method

like image 137
Günter Zöchbauer Avatar answered Oct 21 '22 05:10

Günter Zöchbauer