Reputation: 5241
I've an Angular application where I pass an empty array to Angular-UI Bootstrap Modal. Depends on user choice it may be filled or not with items, up to 1000 objects. All them I display in a list with ng-repeat
. All items in a list are pre-generated, so I can't retrieve them asynchronously for example by using plugin like smart-table.
When user press ok button all generated values returned to controller
from which it was called. Technically all them already there because I pass $scope.items
by reference:
resolve: {
items: function () {
return $scope.items;
}
}
But when I press cancel button I'm erasing all items in an array by invoking $scope.items.length=0;
My problem that it takes a while. In my plunker example below it's barely noticeable but noticeable but in my actual application it's much more noticeable and unacceptable.
My guess that It's due to Angular's two-way binding, it takes a time to clean all watchers but I don't know how to solve this issue, if it can be solved.
My MCVE at plunker here: http://plnkr.co/edit/JwanDxBzh3a7ilEX58z8?p=preview
UPDATE: Tried to use one-time binging, plunker here: http://plnkr.co/edit/PjzHRYiuXFHE1M1Pap6U?p=preview
<li ng-repeat="item in items">
<a href="#"> {{ ::item | date:'yyyy-MM-dd' }}</a>
</li>
as described here: https://stackoverflow.com/a/18791503/947111 it didn't help.
Upvotes: 0
Views: 44
Reputation: 5241
Ok, I was right and I was almost there with Angular's one-time binding
I just used it in a wrong place, and should be used in a ng-repeat
in a such way:
<li ng-repeat="item in ::items">
<a href="#"> {{::item | date:'yyyy-MM-dd' }}</a>
</li>
Thanks to this answer: https://stackoverflow.com/a/23903690/947111
Working plunker located here: http://plnkr.co/edit/XWi6Z0eCXveV58WJfpo6?p=preview
Upvotes: 1