Ad

How To Reset Ng-repeat Block After Reordering Some Of It's Elements?

I have an ng-repeat which uses an array as it's data. Now from UI, I reorder the elements using drag and drop. I have a cancel button which should reset ng-repeat so that the ordering of elements gets back according to the order of the array. I don't know how to do that. Is there any way to achieve that from angularjs or using jquery?

Ad

Answer

One way would be changing the your $scope variable. By doing the following, you preserved your array order and trigger ng-repeat to rerender.

$scope.reset = function(){

    // $scope.data is the variable that holds the array in ng repeat
    $scope.data =  angular.copy($scope.data)

}
Ad
source: stackoverflow.com
Ad