The Best Way to use API


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
            private api: APICall,
            ...) {

this.api.Function().subscribe(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 *ngIf="getData == false">
    Loading ...

This works. But i always have “Loading” before my data. Is there a better way, more efficient ?

Thanks for advice !