The ES6 Promise constructor would look the same Promise(function(resolve, reject){ ... });
The deferred object from $q.defer() comes with the .notify() method, compared to the $q(function(resolve, reject) { ... }) syntax which does not pass in a notify callback to use.
var d = $q.defer();
$window.analytics.setUserId(id, function (response) {
d.resolve(response);
}, function (error) {
d.reject(error);
});
return d.promise;
Prefer following code
return $q(function(resolve, reject) {
$window.analytics.setUserId(id, function (response) {
resolve(response);
}, function (error) {
reject(error);
});
})
Convert from callbacks
Why ?
Prefer following code
when to use defer would be nice.
An use for $q.defer is for cancel a request
Source: http://www.codelord.net/2015/09/24/%24q-dot-defer-youre-doing-it-wrong/