Asynchronous on-change function execution with AngularJS
On-change event is awesome, but when you have a huge things to do when this event happend (for example when the user write something in an input) the GUI will freeze like hell !
I write a directive to do that work asynchronously :
https://github.com/institut-de-genomique/Ultimate-DataTable/blob/master/src/directives/udt-change.js
I use $interval angularjs function (setInterval with an $apply at the end) to control a tick. On every tick I check if I have to run the function.
To run the function on the right context I use a watcher that I disable right after his execution.
The goal I try to achieve is to use promise so that the function don't run concurently, but for now this solution work fine.
Written by Deshayes Yann
Related protips
Have a fresh tip? Share with Coderwall community!
AngularJS pages are long-lived browser apps with the same script risk as a newer single-page app. Third-party code in the template can read forms and values rendered on the page.
Security insights from Cside