Reputation: 18133
It's possible trigger a event when all templates and data are loaded. I have a application made with AngularJS, is finished it but on the production server i have a problem. When a page is loaded the templates are loaded and showed but some times the data comes later and show the elements empty for a while 1~3 seconds (internet connection issues, bandwidth, server load, etc.).
It's possible trigger a event when all is loaded (templates, data, etc.) for show a message loading and hide when the event is fired?
My question is something that can be generally applied as a page can have X amount of directives and these can load additional data
Upvotes: 0
Views: 129
Reputation: 49590
[This is only a partial solution]
Some delays are due to templates loading with, ng-include
.
In your .run
you could collect all the ng-include
s with and wait for all of them to finish:
app.run(function($rootScope){
var loadingIncludeCount = 0;
$rootScope.isLoading = function(){ return loadingIncludeCount > 0; }
$rootScope.$on("$includeContentRequested", function(){ loadingIncludeCount ++; });
$rootScope.$on("$includeContentLoaded", function(){ loadingIncludeCount --; });
$rootScope.$on("$includeContentError", function(){ loadingIncludeCount --; });
}
This would NOT solve for directives loading their templateUrl
s.
Upvotes: 0