Ionic version: (check one with "x")
(For Ionic 1.x issues, please use https://github.com/ionic-team/ionic-v1)
[ ] 2.x
[x] 3.x
[ ] 4.x
I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
Please do not submit support requests or "How to" questions here. Instead, please use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/
Current behavior:
My function calls my REST API service provider to get data from my server. When I display data inside the provider with a console.log() I saw it but when I display the data in my original calling function (the data is passed with a Promise) it's undefined.
Expected behavior:
The data should be displayed in both functions.
Related code:
Here is the method of my provider:
getBusinesses(token: string){
return new Promise((resolve,reject) => {
let request = new HttpRequest('GET',this.listBusinesses,{
headers: new HttpHeaders({
'X-AUTH-TOKEN': token
})
});
this.http.request(request).subscribe(data => {
console.log(data['body']); //works, show my JSON array
resolve(data);
}, err => {
reject(err);
})
});
}
And here is the method of my page function:
private getBusinesses() {
this.cityfidAPI.getBusinesses(token).then(res => {
this.businesses = res['body'];
console.log(this.businesses); //undefined
});
}
Other information:
Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):
cli packages: (C:\Users\cypou\AppData\Roaming\npm\node_modules)
@ionic/cli-utils : 1.19.0
ionic (Ionic CLI) : 3.19.0
global packages:
cordova (Cordova CLI) : 7.1.0
local packages:
@ionic/app-scripts : 3.0.1
Cordova Platforms : none
Ionic Framework : ionic-angular 3.8.0
System:
Android SDK Tools : 26.1.1
Node : v8.6.0
npm : 5.5.1
OS : Windows 10
Environment Variables:
ANDROID_HOME : C:\Users\cypou\AppData\Local\Android\Sdk
Misc:
backend : pro
If I ask that kind of question here it's because I did not get any answer on Ionic Forums or on the Slack channel
Hello! Thank you for opening an issue with us! Would you be able to provide a sample application via GitHub that demonstrates the issue you are having? Thanks for using Ionic!
@kensodemann I can't but the issue is quite simple. I have a provider consuming my REST API. One of its functions gets a list of JSON objects in a JSON array.
I call this provider function in a page controller; the data well arrives to the provider (shown in the console.log()) but not inside the controller...
@Cypaubr - It is highly unlikely that this is an issue within Ionic itself since all of the code you share above is Angular related and not associated with anything provided by the Ionic Framework. This forum is only for Ionic bugs and feature requests, so I am going to close this.
I am willing to take a look at your code, but I can't help debug code I cannot see. This sample does not have to be your actual project code but could be a sample application that you put together using a REST API that you toss together for the demonstration purpose.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.