条件 orderBy 仅在 init AngularJS 上 [英] contidional orderBy only on init AngularJS

查看:21
本文介绍了条件 orderBy 仅在 init AngularJS 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在视图初始化时只运行一次 orderBy 过滤器?我不希望我的列表在运行时重新排序.

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>

推荐答案

改用 orderBy 作为控制器中的过滤器:

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.

这篇关于条件 orderBy 仅在 init AngularJS 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆