I have noticed an interesting behavior in my code. When I define a promise in the service and return it back (promise1 in this case), it does not resolve at all.
However, when I define the promise in the controller (promise2), it works perfectly fine. Why is that?
serv.getDefer = function() {
var defer = $q.defer();
return {
defer: defer,
promise: defer.promise
}
}
var defer1 = serv.getDefer().defer;
var promise1 = serv.getDefer().promise;
promise1.then(function() {
alert('promise1 should work, but doesn't')
})
defer1.resolve();
var defer2 = serv.getDefer().defer;
var promise2 = defer2.promise;
promise2.then(function() {
alert('promise2 works properly')
})
defer2.resolve();