I am seeing angularJS files where in some places reviewer has commented these 3 lines:
var deferred = $q.defer();
deferred.resolve(BrandList);
return deferred.promise;
and replaced with this one:
return $q.when(BrandList);
I would like to understand the difference between two. Do both serve same purpose? Which should be used when?
$q.when
is a single function, and could be passed around. A call to it makes a single expression that can be used about everywhere, while the first snippet with$q.defer()
contains multiple statements. – Ropy