Juri Strumpflohner

RSS

$q.defer: You're doing it wrong

Author profile pic
Juri Strumpflohner
Published

Nice article on Angular deferreds, promises and things you may do wrong.

  • use $q.when(['detail', 'simple']) for simple defereds
  • use promise chaining whenever possible, like return $http....
  • $timeout already returns a promise, so return $timeout
  • use custom made deferreds when wrapping traditional callback APIs (like many of jQuerys)
  • use return $q(function(resolve, reject){ ... }) directly (Angular 1.3+ only)