The Best Way to use API


#1

Hello

I want to know the best way to use an API.
Currently i do this :

  1. i create a variable named getData, it’s a boolean. Default false.
getData: boolean;
  1. i call my api in ionViewWillEnter
constructor(...,
            private api: APICall,
            ...) {
}

this.api.Function().subscribe(res => {
    console.log(res);
    ...
    this.getData = true;
}
  1. 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 !