0

I got an angular 10 app that first start a login page. But before presenting the login fields, I need to check the presence of the web service and check if the app is currently in maintenance. So I need to call a function in my login.component.ts file but when all the contents of the page will be loaded and displayed.

I tried this:

 this.router.events.subscribe((e) => {
   if (e instanceof NavigationEnd) {
      this.NetworkTest();
   }
 });

in my constructor but, it's called a little too early and my main background image is not displayed. Any advice for me?

I also tried ngAfterViewInit with the same result.

Thanks

UDATE1: It is normal that in the NavigationEnd event the binding do not work? The properties is change in background, but the view is not updated.

Pierre-D Savard
  • 529
  • 3
  • 16

1 Answers1

0

ngAfterViewInit seems a good place for your needs.
To make sure background is displayed you can follow this.

To handle displaying login form I suggest creating a flag. Set it to true only if web service is running.
TS: let isWebServiceRunning = false;
HTML: <div *ngIf="isWebServiceRunning">Login Form</div>

Vojtone
  • 137
  • 5