AngularJS promise chain -


i have application should open popup ask confirmation @ user, make ajax cal , close popup.
tried using chain of promise (i've used it, , remember should work in way), seems block after call toreservationservice.confirm($scope.object);. fake service implemented settimeout , $q return promise (in future make ajax call). valid code or didn't undestood how promise works?
popup choose angularui , code this:

 reservationservice.book($scope.object, day)         .then(function(){             var dialogopts = {/* dialog options omitted*/}             return $dialog.dialog(dialogopts).open();          })         .then(function(result){             console.log('confirmed? ', result);             if (result){                 //after line doesn't nothing, if promise resolved                  return reservationservice.confirm($scope.object);             }         })         .then(function(){             //this function never executed             $scope.$emit('object:detail',{object: $scope.object});         }); 

reservationservice:

function confirm(){      var deferred = $q.defer();      settimeout(function(){           console.log('confirming');           deferred.resolve(true)      }, 500);      return deferred.promise; } 

solved change settimeout $timeout angular's service

used $timeout instead of settimeout 'cause works togheter @ angular scope, forcing digest phase (or use $scope.apply() inside settimeout).


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -