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

查看:111
本文介绍了contidional 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');
}]);

参见过滤器文档

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

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