@Yruama wrote:
Hello
I want to know the best way to use an API.
Currently i do this :
- i create a variable named getData, it’s a boolean. Default false.
getData: boolean;
- i call my api in ionViewWillEnter
constructor(..., private api: APICall, ...) { } this.api.Function().subscribe(res => { console.log(res); ... this.getData = true; }
- I use a condtion in my HTML file to check if my api call is finished (either i have an error because i want to display data who does not exist)
<span *ngIf="getData == true"> .... </span> <span *ngIf="getData == false"> Loading ... </span>This works. But i always have “Loading” before my data. Is there a better way, more efficient ?
Thanks for advice !
Posts: 1
Participants: 1