2

When using the deferred method offered by angularjs and querying the database local storage, the "resolve" doesn't seem to work. See the following example. The "then" action is never fired. When trying with a setTimeout instead of the "Person.all()" instruction, it works.

var defer = $q.deferred();

Person.all().list(null, function (persons) {
   defer.resolve(persons);
});

defer.promise.then(function (persons) {
   console.log('resolved');
});

Thanks for helping.

olimungo
  • 67
  • 1
  • 6

1 Answers1

4

For Angularjs's promise, then only fires in digest cycle.

If your Person object is in your service, you can inject $rootScope and call $apply() against it to let then fire.

Tosh
  • 35,955
  • 11
  • 65
  • 55
  • Can you give an example using the code in the question. I have the same problem but new to angular and trying to wrap my head around the promises :) – TimoSolo Jun 19 '15 at 06:36
  • @Tosh, Thanks, got it working. This worked for me: http://stackoverflow.com/a/30932397/253096 – TimoSolo Jun 22 '15 at 08:11