If I have the following functions:
doTask1: function ($scope) {
var defer = $q.defer();
$http.get('/abc')
.success(function (data) {
defer.resolve();
})
.error(function () {
defer.reject();
});
return defer.promise;
},
doTask2: function ($scope) {
var defer = $q.defer();
var x = 99;
return defer.promise;
},
I was told that I can wait for both promises as follows:
$q.all([
doTask1($scope),
doTask2($scope)
])
.then(function (results) {
});
How about if task 2 does not return a promise? I saw in the $ q documentation for AngularJS there is an "when". However, I do not understand how to use it and there is no example.
This is so that I MUST have doTask2, returning a promise, having two lines:
var defer = q.defer()
return defer.promise
or is there an easier way to do this? ll
source
share