0

In my angular 2 application I am fetching navigation data from my database with the help of a web API. I have written the code to fetch the data from the web API in a ngOnInit function in my navigation component.

Is there any way to keep waiting until the data is not received so that the user doesn't see the page without the navigation menus?

Hakan Ozbay
  • 4,639
  • 2
  • 22
  • 28
Yashpal S
  • 299
  • 4
  • 16
  • 3
    ye, use `*ngIf` in your navigation menu. E.g: `*ngIf="navigationData"` – FAISAL Sep 05 '17 at 11:12
  • 1
    Possible duplicate of [Wait for Angular 2 to load/resolve model before rendering view/template](https://stackoverflow.com/questions/34731869/wait-for-angular-2-to-load-resolve-model-before-rendering-view-template) – mxr7350 Sep 05 '17 at 11:16

2 Answers2

0

You can put *ngIf or [hidden] in the view part untill data is gets loaded from the web API, once data get successfully you can toggle variable and view data accordingly like this

viewData: boolean = false;

ngOnInit(){
  ...httpCall(){
    if(success)
      this.viewData = true;
  }
}

In the view part set condition on the BoxListContainer

<div *ngIf='viewData'>
  ....... your content here
</div>
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
0

In the OnInit function use a spinner to disable the entire page as the content loads. Make an HTTP call to the API and in the complete callback disable the spinner.

Vinorth
  • 968
  • 8
  • 13