angularjs - Catching Angular promise success response twice -


it seems console output be:

this first response second response 

because success function of inner method invoked first. correct assumption? order guaranteed?

app.controller("ctrl", function($scope,$http) {      var geturl = function () {            var config = {               method: 'get',               url: 'some.txt'           };             return $http(config)               .success(function (response, status, headers, config) {                     console.log('this first response');                })               .error(function (data, status, headers, config) {               });       };           var init = function () {         var promise = geturl();         promise.then(            function() {                console.log('this second response');            });     };      init();   }); 

yes, because $http return promise , above promise chaining.

although might better use $http.then(success,error).then(success,error);


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -