Wednesday, 8 February 2017

TypeError: $http.post(...).success is not a function

Due to angular 1.5.x upgrading, you cannot use success callback function anymore for $http.


The replacement of this is promise.

For example:

$http.post().success(function (){...........}).error(function() {........});

Above code need to be changed to :

$http.post().then(function() {...........}, function() {...........})


However, there is one thing i want to highlight is, the callback parameter.

You used to get the data directly from success callback, but after you change to promise, then the parameter you get is the response object, the data you need is response.data.



No comments:

Post a comment