Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular.js - is using $timeout dirty workaround?

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();
    });
}
like image 342
sanyooh Avatar asked Dec 06 '25 09:12

sanyooh


1 Answers

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

like image 90
Steve Drake Avatar answered Dec 07 '25 21:12

Steve Drake