Thursday, June 15, 2017

$http.get(…).success is not a function

When i was working on application using angular 1.6.4, i was using the $http to get the data from the server. So i used the below line of code

$http.get("data/places.json").success(function (results) {
$scope.places = results.data;
});

but it was throwing an error saying $http.get(…).success is not a function. When i browse through the angular documents and net, it seems to be that, the function success and error has been deprecated from 1.5, instead you have to use then method. The then() method takes two arguments: a success and an error callback which will be called with a response object.

$http.get("data/places.json").then(function (success) {
$scope.places = success.data;
},
function(error){
//do something
});


Happy Programming...!!!

No comments:

Post a Comment