contidional orderBy only on init AngularJS

2019-06-25 17:01发布

How can I run orderBy filter only once when my view is initialized? I don't want my list to be reordered during runtime.

<li ng-repeat="service in quote.services | orderBy:'index'" ></li>

1条回答
SAY GOODBYE
2楼-- · 2019-06-25 17:43

Use the orderBy as a filter in your controller instead:

app.controller('DemoCtrl', ['$scope', '$filter', function($scope, $filter){  
    $scope.quote.services = $filter('orderBy')($scope.quote.services, 'index');
}]);

See the filter docs for all the options.

查看更多
登录 后发表回答