I have been developing a scrollspy module for AngularJS, and I am facing the challenge of keeping the scrollspy data up to date when dealing with dynamic content on the page. What is the best approach in AngularJS to address this issue?
Is it advisable for any directive that manipulates the DOM to $broadcast
an event that the scrollspy module can listen for, enabling it to update its position data?
Alternatively, should the scrollspy module periodically check for changes in scrollHeight using $timeout
every x seconds?
Or perhaps there is a way to bind and monitor changes in DOM attribute values (such as offsetTop
, offsetHeight
, scrollHeight
, rather than data attributes)?
Update: Code base added to GitHub