Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

The Best Way to use API

$
0
0

@Yruama wrote:

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 !

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>