AngularJS promises notify not working

angularjs, promise

Solution

I managed to get it working by wrapping notify in $timeout function:

$timeout(function() {
  deferred.notify('In progress')
}, 0)

Looks like you cant call notify before you return promise object, that kinda makes sense.

Problem

I have the following controller code: ``` .controller('Controller1', function ($scope, MyService) { var promise = MyService.getData(); promise.then(function(success) { console.log("success"); }, function(error) { console.log("error"); }, function(update) { console.log("got an update!"); }) ; ``` } And in my services.js: ``` .factory('MyService', function ($resource, API_END_POINT, localStorageService, $q) { return { getData: function() { var resource = $resource(API_END_POINT + '/data', { query: { method: 'GET', isArray: true } }); var deferred = $q.defer(); var response = localStorageService.get("data"); console.log("from local storage: "+JSON.stringify(response)); deferred.notify(response); resource.query(function (success) { console.log("success querying RESTful resource") localStorageService.add("data", success); deferred.resolve(success); }, function(error) { console.log("error occurred"); deferred.reject(response); }); return deferred.promise; } } }) ``` But for some reason the `deferred.notify` call never seems to execute and be received within the controller. Have I don't something wrong here? I'm not sure how to get the notify to execute.

Original source