The .success syntax was correct before Angular v1.4.3.
For versions prior to Angular v.1.6, you must use the then method. The then() method takes two arguments: a success and an error callback that will be called with the response object.
Using the then() method, attach the callback function to the returned promise .
Something like that:
app.controller('MainCtrl', function ($scope, $http){ $http({ method: 'GET', url: 'api/url-api' }).then(function (success){ },function (error){ }); }
See link here.
Shortcut also available.
$http.get('api/url-api').then(successCallback, errorCallback); function successCallback(response){
It is expected that the data received from the response will be in JSON . JSON is a great way to transfer data and is easy to use in AngularJS
The main difference between 2 is that the .then() call returns a promise (resolved with the value returned from the callback ), and .success() is a more traditional way of registering callbacks and does not return a promise .
Mihai Alexandru-Ionut Dec 15 '16 at 16:56 2016-12-15 16:56
source share