← all articles

$q.defer: You're doing it wrong

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)
Juri Strumpflohner
Juri Strumpflohner
Architect. Educator. Builder.
Sr. Director of Developer Experience at Nx

Stay in the loop

Don't miss any of my content. No spam. I'm not a grifter.