Hi Can any one please help me about this service call methods in angular Js.
what is the difference between Success function and Then Function?
Which function is use in which condition
Hi Can any one please help me about this service call methods in angular Js.
what is the difference between Success function and Then Function?
Which function is use in which condition
As per the documentation: https://docs.angularjs.org/api/ng/service/$http
The .then()
function is the standard way to register callbacks for when a promise has been resolved - see https://docs.angularjs.org/api/ng/service/$q for angular's implementation of promises.
The promise returned by $http
is a promise for a Response:
$http.get('http://example.com').then(function successCallback(response) {
response.data, response.status, and so on
})
Oftentimes, all you need from the Response is just the data. The callbacks registered via .success()
will receive just data
:
$http.get('http://example.com').success(function successCallback(data) {
data.??? depending on what you return
})
In angular.js we have $http and $q , both returns the promise object.
The main difference between $httpPromise and $q.defer().promise is that $http provide you two more function success and error. So you can't use success and error to a function returning $q.defer().promise.
One difference in context of $http is as Sacho explained below.