I am having error as
TypeError: Cannot set property 'data' of undefined
I try fetch the data from rest api in angularjs using Http get method, Here the code
getData(){
this.http({method: 'GET',url:URL})
.then(function(response) {
console.log(response.data.id);
this.data=response.data;// these line shows the error(TypeError: Cannot set property 'setdata' of undefined)
});
}
Here console.log(response.data.id); print the id as 123456789 and console.log(response.data); print the entire JSON data.
But While assign the
response.datatothis.datashows error. But assign theresponse.datatovar datadoesn't show error.
Please help me to store the response.data in this.data
this.data(function(response) { ... }).bind(this)