I have a function which I want to call after page content is loaded. I read about $viewContentLoaded and it doesn't work for me. I am looking for something like
document.addEventListener('DOMContentLoaded', function () {
//Content goes here
}, false);
Above call doesn't work for me in AngularJs controller.
Angular < 1.6.X
Angular >= 1.6.X
I found that if you have nested views - $viewContentLoaded gets triggered for every of the nested views. I've created this workaround to find the final $viewContentLoaded. Seems to work alright for setting $window.prerenderReady as required by Prerender (goes into .run() in the main app.js):
I was using
{{myFunction()}}
in the template but then found another way here using$timeout
inside the controller. Thought I'd share it, works great for me.I use
setInterval
to wait for the content loaded. I hope this can help you to solve that problem.You can directly call it by adding
{{YourFunction()}}
after HTML element.Here is a
Plunker Link
.