contidional orderBy only on init AngularJS

微笑、不失礼 提交于 2019-12-10 17:15:37

问题


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:


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.



来源:https://stackoverflow.com/questions/35615976/contidional-orderby-only-on-init-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!