Mukesh Kumar
Mukesh Kumar

Reputation: 2376

How to apply javascript code once component rendering done in angularjs 1.5?

I have component, created in angularjs 1.5. I want to add some logic in javascript once my whole component DOM is ready.

I have tried lifecycle function of component $postLink. But it is not working.

function ModelTableController($scope, $rootScop) {
        var $ctrl = this;

        $ctrl.data = null;
        $ctrl.MetricLibraryCode = 'QUENTANT';
        $ctrl.rowSelected = null;


        $ctrl.$postLink = function () {
            console.log('postlink');
            var tr = document.querySelectorAll('tr');
            for (var i = 1; i < tr.length; i++) {
                tr[i].style.backgroundColor = i % 2 ? '#2C3135' : '#262a2e';
            }
        };        
    }
})();

Please suggest how can I achieve this?

thanks

Upvotes: 0

Views: 38

Answers (1)

Pengyy
Pengyy

Reputation: 38171

try with $timeout, this will add it's callback to scheduler and will be executed after document is ready.

$timeout(function(){
  // do things here.
})

Upvotes: 1

Related Questions