Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make jQuery Deferred / Promises and AngularJS $q Deferred / Promises compatible

I have some old JavaScript libraries that use jQuery promises as return objects from function calls. I'm now using AngularJS which uses the $q service (inspired by the Q library). Does anybody have some generic JavaScript code to make these two different promise implementations compatible, so that jQuery promises can be used as if it where $q promises? Or something similar?

like image 729
Maarten Docter Avatar asked Sep 23 '13 08:09

Maarten Docter


1 Answers

Third party promises can be wrapped with $q.when(thirdPartyPromise) to be converted into $q promises. When the thirdPartyPromise resolves, the $q promise resolves accordingly and $scope.$apply() is called.

like image 147
Nikos Paraskevopoulos Avatar answered Oct 21 '22 03:10

Nikos Paraskevopoulos