This is also a general question.
In my example I have to edit the DOM on a Leaflet Map to manipulate the appearance of the legend. We used $timeout as a workaround because the map isn't generated fast enough to get the elements in the map.
So I wanted to know if this is a dirty/messy workaround and if this could be done better than using $timeout?
As suggested some code. The activate function is one of the initiating functions of the map.
controller.js
function activate() {
projectService.getMarkers(vm, 'projectsData');
$timeout(function() {
manipulateLegend();
});
}
As far as I understand this is fine, I think the name can lead people into thinking its a bad pattern.
Have read of
http://blogs.microsoft.co.il/choroshin/2014/04/08/angularjs-postdigest-vs-timeout-when-dom-update-is-needed/
and this is interesting
http://lorenzmerdian.blogspot.co.uk/2013/03/how-to-handle-dom-updates-in-angularjs.html
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