0

I have an Angular 2 service that does a basic HTTP call to give me back a JSON Object. Once I have that object I do numerous calculations (in my service) that are needed by multiple components in my App. My problem is the components render before the data is retrieved and parsed.

How do I get my components to not load, until the data is retrieved and parsed?

(I've seen the *ngIf="data" solution, but that seems more like a workaround than a permanent fix?)

Starboy
  • 1,635
  • 3
  • 19
  • 27

1 Answers1

0

There are few valid ways:

  1. initialize fields with defaults i.e. []
  2. Use *ngIf
  3. Use css visibility:hidden
  4. Use Resolver guard to fetch and process data.
  5. Use NgComponentOutlet and create component dynamically.
kemsky
  • 14,727
  • 3
  • 32
  • 51