Search code examples
javascriptjqueryangularjsangularjs-ng-repeat

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?


Solution

  • 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)
    
    }