Angular 2 render template after the PROMISE with data is loaded
Asked Answered
E

1

7

I'm new to AngularJS 2.0, basically I'm loading data through Promise in constructor, but the template is rendered before the promise is resolved.

Any idea how to achieve this?

Thanks, M.

Eadie answered 14/10, 2015 at 22:47 Comment(2)
You should provide code enough to see what could be wrong.Briny
Possible duplicate of Wait for Angular 2 to load/resolve model before rendering view/templateBarr
C
4

You can test the data before using it.

<ul *ngIf="data">
  <li *ngFor="let item of data">{{item.value}}</li>
</ul>
Coralline answered 15/10, 2015 at 10:36 Comment(1)
A good practice is to initialize a variable with false value that says if the content is loaded or not. Something like isDataLoaded. Then, after content loads, set it to trueSouza

© 2022 - 2024 — McMap. All rights reserved.