And on top of this, why are $scope
values set BEFORE $q.all
is called completely ignored?
Function within main controller:
$scope.apply = function (security) {
var entity = shareDataService.getModalEntity();
var depot = shareDataService.getModalDepot();
$scope.loaded = false;
var myDataPromise;
if (entity == "NULL") {
myDataPromise = getDataService.getDataFromREST(security);
} else {
myDataPromise = $q.all(getDataService.keepICorrect(security));
};
myDataPromise.then(function () {
//DO STUFF
}, function errorCallback(response) {
//DO MORE STUFF
});
}
And my keepICorrect()
function in my service (which is a closure):
keepICorrect: function (security) {
var promises = [];
for (var i = 0 ; i < entity.length; i++) {
promises.push(this.getDataFromREST(security, i));
}
return promises;
},
However when the $scope.apply()
function is executed, nothing happens. Boolean $scope.loaded
does not activate on the scope and no exception is thrown (which is what I was expecting). Why is this?
I've edited the code and made my controller function Apply
check if entity = "NULL"
, and this seems to have solved the issue of whether it is an array or not. Still doesn't answer my question as to why if q.all
is not returned an array of promises, does nothing happen in the function it is called in, even if before q.all
is called.