Friday, September 12, 2014

angularJs run code after all elements/page has loaded

In some cases there is jQuery that needs to be run only after other angular directives/the page itself have completed (for example you may need to use the height of a div that changes based on content added by angular, or even access elements by class which is added by ng-class).

In this case, you use an empty timeout function in the angular controller and it will only run after all other angular elements have completed loading/processing.
<div id="myDiv" ng-controller="MyCtrl">

var MyCtrl = [
    '$scope', '$timeout',
    function ($scope, $timeout) {
        $timeout(function () {
            // code here
        }, 0);

No comments:

Post a Comment