The directive is calling $timeouteach time it is executed. When many select2 boxes are present on the same page, and within a complex angular application, this has a major impact on performances (since each $timeout does a $rootScope.$digest), and also causes flickering with each select2 being populated at a time, instead of all being displayed at the same time.
I fixed that by using scope.$evalAsync (angular 1.2+) instead of $timeout in my project and it works like a charm. But this change breaks the tests, so that may not be the proper way to fix that.
Also, note that using $timeout(cb, 0, false) at least doesn't trigger an extra $apply per occurence, and the tests still pass (but even if that fix the performances issue, that doesn't prevent the flickering issue).
PS: to be retro-compatible, you can use
var lateApply = scope.$evalAsync || $timeout;
lateApply( ... );
The directive is calling
$timeout
each time it is executed. When many select2 boxes are present on the same page, and within a complex angular application, this has a major impact on performances (since each$timeout
does a$rootScope.$digest
), and also causes flickering with each select2 being populated at a time, instead of all being displayed at the same time.I fixed that by using
scope.$evalAsync
(angular 1.2+) instead of$timeout
in my project and it works like a charm. But this change breaks the tests, so that may not be the proper way to fix that.Also, note that using
$timeout(cb, 0, false)
at least doesn't trigger an extra$apply
per occurence, and the tests still pass (but even if that fix the performances issue, that doesn't prevent the flickering issue).PS: to be retro-compatible, you can use