我有多个删除请求,前面有OPTIONS
转机前请求。但是控件在$q.all
请求之后进入OPTIONS
。这是我的代码:
companyMasterC.confirmDelete = function(ev, text) {
simpleDialog.verifyDelete(ev, text).then(function() {
companyMasterC.deletePromise = companyMasterC.deleteSelected().then(function(response) {
companyMasterC.getCompanies();
}, function(error) {
console.log(error);
});
});
};
companyMasterC.deleteSelected = function(){
var promises = companyMasterC.selectedRows.map(function(selectedRow) {
return company.delete({id:selectedRow.id});
});
return $q.all(promises);
};
以下是“网络”标签中发生的情况:首先,执行OPTIONS
请求,然后执行GET
请求companyMasterC.getCompanies();
执行DELETE
请求时应执行的操作。并且在执行GET
请求DELETE
请求之后。
答案 0 :(得分:2)
更改
return company.delete({id:selectedRow.id});
到
return company.delete({id:selectedRow.id}).$promise;
修改后的代码:
companyMasterC.confirmDelete = function(ev, text) {
simpleDialog.verifyDelete(ev, text).then(function() {
companyMasterC.deletePromise = companyMasterC.deleteSelected().then(function(response) {
companyMasterC.getCompanies();
}, function(error) {
console.log(error);
});
});
};
companyMasterC.deleteSelected = function(){
var promises = companyMasterC.selectedRows.map(function(selectedRow) {
return company.delete({id:selectedRow.id}).$promise;
});
return $q.all(promises);
};