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.

danday74
  • 52,471
  • 49
  • 232
  • 283
Milan Klíma
  • 91
  • 1
  • 2
  • You should provide code enough to see what could be wrong. – Eric Martinez Oct 14 '15 at 22:55
  • Possible duplicate of [Wait for Angular 2 to load/resolve model before rendering view/template](http://stackoverflow.com/questions/34731869/wait-for-angular-2-to-load-resolve-model-before-rendering-view-template) – Wouter Vanherck Mar 23 '17 at 13:15

1 Answers1

4

You can test the data before using it.

<ul *ngIf="data">
  <li *ngFor="let item of data">{{item.value}}</li>
</ul>
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
yang lin
  • 130
  • 2
  • 2
    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 `true` – Roger Ramos Nov 13 '17 at 18:27