angular-ui / ui-select2

AngularJS wrapper for select2 (deprecated, use angular-ui/ui-select)
https://github.com/angular-ui/ui-select
MIT License
596 stars 443 forks source link

$timeout performances impact #268

Open floribon opened 10 years ago

floribon commented 10 years ago

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( ... );
tjacobsx22 commented 9 years ago

+1 I've encountered the same issue.