Hello, I have a provider for consuming my REST API but I have a problem when I try to get the response from it.
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 called by my view:
private getBusinesses() {
this.cityfidAPI.getBusinesses(token).then(res => {
this.businesses = res['body'];
console.log(this.businesses); //undefined
});
}
As you see, I have 2 console.log() on dispays the list and the second displays ‘undefined’ and I don’t know why…
Cheers!