You can use controllers.
HTML:
<div data-ng-controller="includeCtrl" data-ng-include="'/partials/file.html'"></div>
Angular:
app.controller('PageCtrl', function () {
$scope.includesLoaded = 0;
$scope.totalIncludes = 10; //The total number of includes you have
$scope.$watch(function($scope) { return $scope.includesLoaded },
function(newValue, oldValue) {
if(newValue === $scope.totalIncludes) {
// Your code here
}
}
);
});
app.controller("includeCtrl", ["$timeout",
function($timeout) {
var init = function() {
$timeout(function() {
$scope.includesLoaded++;
}, 0);
};
init();
}
]);
Explanation:
By keeping a variable with the number of includes loaded you can tell if all of them were loaded.
$scope.$watch
listens to differences in the variable returned in the first function and reacts to it by calling the second.
Now, $scope.$watch
will only fire during an Angular digest cycle. $timeout
calls the cycle, but it might not be needed, I didn't test the code.
Since PageCtrl
must be the top-level controller of the application, $scope.includesLoaded may be available for the other controllers but, again, I'm not sure. If it does not work, use $rootScope instead.
pankajparkar's answer is way better, though. Just my 2 cents for reference.