I would like understand the difference between then callback and success callback when called over http get. When i use then callback it returns the data but with success callback it doesnt. Below is the code
Then callback
$http.get(url).
then(function(response) {
response.data.data;});
Success callback
$http.get(url).
success(function(response) {
response.data;});
Your issue seem to be around this:
$http.get('/someUrl'). success(function(data, status, headers, config) {
it's a different return from then
,
then
method to register callbacks, and these callbacks will receive a single argument – an object representing the response
In other words, you should be doing this:
$http.get(...).success(function(data){ console.log(data) })
$http.get(...).then(function(response){ console.log(response.data) })
And of course the chaining differences, but doesn't seem related to your issue:
then()
If you chain then()
, the callbacks will run sequentially after each one is done, because it returns a new promise object on each chain
success()
(deprecated* along with error()
)If you chain success()
calls, the callbacks will be ran in parallel, because it returns the original promise object
*success
and error
are deprecated, see Deprecation Notice section in $http docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With