Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48983

How to solve undefined promises in Ionic Cordova?

$
0
0

In my web browser, the Promise object is “fulfilled”, the result is a value, but when I build it in the mobile app the Promise object is “pending” (working), the result is undefined.
Here is my code below

api_url:any;

async getApiURLPromise() {
  return await new Promise(resolve => {
    this.http.get("https://www.sample_api.com/api/production")
      .subscribe(data => {
        this.api_url = data['apiurl'];
        console.log("PROMISE TO HER THIS API URL - " + this.api_url);
        resolve(this.api_url);
    });
    }).catch(error => {
      console.log("PROMISE REJECTED BECAUSE YOU BROKE IT - " + error 
      + " - " + JSON.stringify(error));
    });
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48983

Trending Articles



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