For some reason, I cannot access the response from a request in an Angular project. Even if I can print it on console, I can access data.status and data.response, but when I try data.response.entries, I have the following issue.
My component:
transportantions: any[]; //this is on the start of my component together with the rest of my variables
getTransportations() {
let loader = this.loadingController.create({
content: 'Getting data...'
});
loader.present();
this.wpApi.getTransportations()
.then(function (data) {
console.log(data);
if ( data.status == 200 ) {
this.transportantions = data.response.entries;
loader.dismiss();
} else {
console.log('Something was wrong. Error status ' + data.status);
}
})
.catch(function (err) {
loader.dismiss();
console.log('something was wrong: ' + err);
});
}
This is the output from console.log(data)
{
"status": 200,
"response": {
"total_count": "242",
"entries": [
{
...
},
{
...
},
{
...
},
...
]
}
}
And the error I get is:
something was wrong: TypeError: Cannot set property 'transportantions' of undefined
data.response. What you are getting ? Are you getting correct output?