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.
I had to implement this logic while handling with google charts. what i did was that at the end of my html inside controller definition i added.
and in that function simply call your logic.
Running after the page load should partially be satisfied by setting an event listener to the window load event
Inside the
module.run(function()...)
of angular you will have all access to the module structure and dependencies.You can
broadcast
andemit
events for communications bridges.For example:
According to documentation of $viewContentLoaded, it supposed to work
$viewContentLoaded
event is emitted that means to receive this event you need a parent controller likeFrom
MainCtrl
you can listen the eventCheck the Demo
fixed - 2015.06.09
Use a directive and the angular element
ready
method like so:js
html
or for those using controller-as syntax...
The benefit of this is that you can be as broad or granular w/ your UI as you like and you are removing DOM logic from your controllers. I would argue this is the recommended Angular way.
You may need to prioritize this directive in case you have other directives operating on the same node.
If you want certain element to completely loaded, Use ng-init on that element .
e.g.
<div class="modal fade" id="modalFacultyInfo" role="dialog" ng-init="initModalFacultyInfo()"> ..</div>
the initModalFacultyInfo() function should exist in the controller.
Above method worked for me