I am trying to get data assigned to a $scope variable. Inside my $promise.then() function it is displaying correctly but outside the function it shows as undefined. The foll
This code will help you to fetch data and resolve with promise, please note fetch data will only work after then call...
getData(){
const promise = this.httpClient.get(this.PHP_API_SERVER+'/api/books').toPromise();
promise.then((data)=>{
console.log("Resolved: " + JSON.stringify(data));
return JSON.stringify(data);
}, (error)=>{
console.log("Rejected " + JSON.stringify(error));
})
}