我總是在控制檯看到如何回報承諾風趣h動車組承諾:從多個承諾
var _addOrDeleteUser = function (userId, addToProjects, removeFromProjects) {
var deferred = $q.defer();
var promises = [];
promises.push(projectResource.addUserToProjects({ userId: userId }, addToProjects, function (result) {
console.log("addUserToProjects");
deferred.resolve();
return result;
}));
promises.push(projectResource.deleteUserFromProjects({ userId: userId }, removeFromProjects, function (result) {
console.log("deleteUserFromProjects");
deferred.resolve();
return result;
}));
return $q.all(promises);
}
你能提供這兩種方法的內容,以及好嗎? 'projectResource.addUserToProjects'和'projectResource.deleteUserFromProjects' –
另外,你的'deferred'似乎什麼都不做 - 你可以刪除'var deferred = $ q.defer();'和那兩個'deferred'的行。 resolve();' –
你確定函數'addUserToProjects'和'deleteUserFromProjects'返回一個promise嗎?附: https://jsfiddle.net/hLk0oruy/ –