I have a question regarding chaining promise.
Here's my code:
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);
})
}
Basically I need to call the updateId
method from myService
every time I add or remove a product. So the steps are as follows:
Update ID
Remove product if there is a type 'New'
Update ID
Add product
How do I change this? Thanks for the help!