我有一个关于链接承诺的问题。如何链接承诺
这里是我的代码:
var removeProducts = function(id) {
anotherService.removeProducts(id); // this will return a promise.
}
var addProduct = function(id) {
myService.addProduct({id: id})
}
$scope.pickProduct = function() {
myService.updateId({'id':123}).$promise.then(function(items) {
items.categories.filter(function(category) {
if (category.type === 'NEW') {
removeProducts(items.id);
}
})
//this is the part I don't know how to proceed. I need to make sure
//the product is removed before first and update ID second so I can add
//another product.
addProduct(item.id);
})
}
基本上我需要调用从myService
的updateId
方法我每次添加一次或删除产品。所以步骤如下:
Update ID
Remove product if there is a type 'New'
Update ID
Add product
我该如何改变?谢谢您的帮助!
在语句'addProduct(item.id)'中,从哪里获得'item'?或者是一个错字? – georgeawg
有关链接承诺的信息,请参阅[使用'$ q'的角度执行顺序](http://stackoverflow.com/questions/34324153/angular-execution-order-with-q/34326388)。 – georgeawg