I'm constantly facing issues with $q
Here is an instance where the .then
is triggered immediately
function performAction() {
var deferred = $q.defer();
var modalInstance = $modal.open({
template: '<p>this is a modal</p><a ng-click="ok()">ok</a>',
controller: function ($scope, $modalInstance) {
$scope.ok = function () {
$modalInstance.close();
};
}
});
modalInstance.result.then(function () {
console.log('ok');
deferred.resolve();
}, function () {
console.log('Modal dismissed');
});
return deferred.promise;
}
In another part of the code:
$scope.service.performAction().then(
$scope.variable = 5
);
http://jsfiddle.net/IngoVals/stqwanhm/
When I tried to replicate a similar scenario in Fiddle, I encountered this issue where .then did not execute. Can anyone explain what might be happening here?