My understanding of $q
in AngularJS is that it runs every time I refresh my page, similar to using a function in ng-init
.
Here is the code for $q.all
that I have:
$q.all([$scope.getCart(), $scope.getCategory(), $scope.getMenu(), $scope.getRestaurant()]).then(function(data){
$scope.cart = data[0].cart;
$scope.cartItems = data[0].cartItems;
$scope.delDay = data[0].delDay;
$scope.delTime = data[0].delTime;
$scope.cat = data[1];
$scope.itemData = data[2];
$scope.rest = data[3];
});
Each time I refresh the page, these functions are called and the data is added to my $scope
. This behavior is as expected.
I am now wondering how I can manually invoke $q
from another function like this:
$scope.notEnoughTime = function () {
if (year = 2015) {
// need to manually trigger $q here
// to call all the functions and update the scope data
}
}