Angularjs Goodness – How to run Jquery scripts/apply styles after the table has been populated by ngRepeat
It is touch sometimes for JQuery and Angular to coexist esp. when there are external jquery scripts which are also manipulating the dom and Angular is reluctant to give the control over the DOM. We had a jquery script which was applying some styles on the the table, but with ngRepeat getting used in angular, those styles were not getting applied, as ngRepeat used to come later and manipulate the DOM its way.
Needed a way so that I can run the my jquery fuction only after the table has been completely reloaded, intially we went with $timeout() and in that invoked the jquery function, but was very unreliable as you never know when angular has finished loading the table.
The $timeout internally calls apply() which will notify angularjs about DOM has changed externally and it has to run its digest cycle; but as mentioned above its unreliable, And I need to know
The way out of this is creating a directive which will listen to the $last property of ngRepeat , which represents the last element, and once the $last is invoked, go ahead and invoke the controller which can reload the custom jquery.
Here is the code which will explain it much better..
Originally published in 2014
Comments
Post a Comment