每当使用路由解析器在路径中传递了dropDraft时,我都试图删除草稿数据并加载原始数据。
我的用例是删除承诺必须在获取数据之前完成。
Delete和Get正在运行paralley。如何制作
resolve: {
data: [
'$route',
'$q',
'service1',
function ($route, $q, service1) {
var deferred = $q.defer();
var getDataPromise = service1.getData($route.current.params);
if ($route.current.params.deleteDraft) {
var deleteDraftPromise = service1.deleteDraft($route.current.params.id);
deleteDraftPromise.then(function () {
getDataPromise.then(function (resultData) {
deferred.resolve(resultData);
});
});
}
else {
getDataPromise.then(function (resultData) {
deferred.resolve(resultData);
});
}
return deferred.promise;
}
]
答案 0 :(得分:0)
一个接一个地解决
resolve: {
data: ['$route', '$q', 'service1', function ($route, $q, service1) {
var deferred = $q.defer();
if ($route.current.params.deleteDraft) {
service1.deleteDraft($route.current.params.id, function (res) {
service1.getData($route.current.params, function (argument) {
deferred.resolve(argument);
});
});
} else {
service1.getData($route.current.params, function (argument) {
deferred.resolve(argument);
});
}
return deferred.promise;
}]
}