I have a list of items, each has a unique id
$scope.arr = [{val:0,id:'a'},{val:1,id:'b'},{val:2,id:'c'}];
Each item is absolute positioned according to their $index
<div class="item" ng-repeat="item in arr track by item.id"
ng-style="getAbsPos($index)" >{{item.id}}</div>
All I wanted is swapping arr[0]
and arr[2]
in the array, and display a moving animation of this action. It turns out to be very difficult.
I assume this css would work since the list is tracked by id
.item{
transition:all 3000ms;
}
but somehow angular decides only moving one of items' dom and re-create the other one (why?!). As result, only one item is animated.
= Question =
Is there a solution to fix this problem, so both items will be animated when they swap? Thanks.
(Have to actually swap the item's position in the array, so it can be easily accessed by correct index all the time)
= See Plunker demo =