My understanding of $$postDigest is that it's an opportunity to fire a callback after the current digest cycle has finished - without causing a new digest cycle in the process.
However, does that mean that all DOM effects caused by the current digest cycle are visible to the callback in the $$postDigest.
Given the pseudo code below:
//some code affecting the width of an element and triggering a digest loop
myModel.width = 10; //bound back to dom element with id = 'myId'
$$postDigest(function(){
//some callback running after the most recent digest loop
//gets the width of a DOM element by reading the value directly from the DOM element
//that was changed in the previous digest loop
var width = $('#myId').width();
//Will width always be 10 here?
});
Let's assume a bound value in the current digest loop causes the width of a DOM element to change. Then, in $$postDigest I fire a callback with some legacy code that reads the changed width from the DOM element directly. Is it safe to read the value from the DOM element in the $$postDigest since it's supposed to happen after the digest cycle has finished. In other words should the browser be done rendering the effects of the digest cycle by the time the $$postDigest runs?
I am not a fan of this pattern, but have to integrate with some non angular code
$$postDigest
fires a callback function after the current $digest
cycle is complete, which means it runs once after all the watches manipulate the DOM and before the browser renders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With