I am building a web application using Angular, and I am trying to find a way to wait until all of the data-ng-include
elements have been evaluated and the inclu
You can use a JQuery Promise, and fulfill this promise within your angular root controller. Setup the promise before the angular controller or jquery code runs:
var AppReadyDeferred = $.Deferred();
var AppReadyPromise = AppReadyDeferred.promise();
Inside your angular controller once everything is ready, do
AppReadyDeferred.resolve();
And in your jQuery code wait for it to be resolved
window.AppReadyPromise.done(() => {
// Angular is ready to go!;
});
on content loaded:
$rootScope.$on('$includeContentLoaded', function() {
//do your will
});
on content requested:
$rootScope.$on('$includeContentRequested', function() {
//...
});
Use ng-cloak to delay templates being shown before compilation. You can also add a hidden field as the very last child to your html element that has ng-cloak (better to use it in body tag or wherever your ng-app starts) and then you can check for existence of this hidden element in an interval loop
Your hidden field part would be like this
<div ng-include="'ngtplhidden'"></hidden>
<script type="text/ng-template" id="ngtplhidden">
<span id="elemidToCheckInAnIntervalFunc"></span>
</script>
I am certain that this is not the correct way to do it but....
Putting the below function in my view controller, ran the function after the view had loaded in my application. I believe that the function is run in the next digest cycle following the view load (correct me here if wrong), so it is run once the page is formed.
setTimeout(function(){
//do this after view has loaded :)
console.log('success!');
}, 0);
Its possible you could chain these together via callbacks and/or use an async parallel library to execute another function, after each of the views setTimeouts had returned.
I think the appropiate answer is NO. You have to change the way you are looking at your app and Model and adapt it to the "angular way". Most likely there is a healthier way to achieve what you need. If you need to attach events to elements probably you may want to use a directive but of course I do not have enough information to judge at this stage what is best.
angular.module along with directives is a good option to explore.
Here is a plunker demo on how to use both with a JQUERY plug in:
http://plnkr.co/edit/WGdNEM?p=preview
Here is a an example with a directive on a separate file:
http://plnkr.co/edit/YNBSWPLeWqsfGvOTwsMB?p=preview
You can try using document.onreadystatechange
document.onreadystatechange = x => {
console.log('ready!');
}