For an angular project, I need to invest promises, and I encounter situations when I'm not sure what I'm doing. Here is one of my codes:
return Action1().then(function (data) { var defer = $q.defer(); if (data.condition) { $q.all([Action2(), Action3(), Action4()]).then(function () { defer.resolve(); }); } else { defer.reject("error_code"); } return defer.promise; });
Action1, Action2, Action3, and Action4 work with promises. These are many promises, and the actions depend on the conditions. Can I do this and be sure that my main function will always be solved or rejected?
I read that we can pass a promise inside the resolution function. Can I do this and this is the same as above:
return Action1().then(function (data) { var defer = $q.defer(); if (data.condition) { defer.resolve($q.all([Action2(), Action3(), Action4()]); } else { defer.reject("error_code"); } return defer.promise; });
source share