在Angular JS中排序

时间:2016-02-16 20:45:54

标签: angularjs angularjs-orderby

我想在卡片下面订购

<div ng-app="myApp" ng-controller="Ctrl">
    <div ng-repeat="card in myCards | orderBy:'card'">
       <businesscard>{{card}}</businesscard>
    </div>
</div>

angular.module('myApp', [])
.controller('Ctrl', function($scope) {
    $scope.myCards = ['J', 'S', 'A'];
});

我期待的结果是, 一个 Ĵ 小号

相反,我得到了 Ĵ 小号 甲

2 个答案:

答案 0 :(得分:3)

要按值排序,只需向orderBy提供参数(参见orderBy array item value in Angular ng-repeat):

<div ng-repeat="card in myCards | orderBy">

答案 1 :(得分:0)

试试这个

<div ng-repeat="card in myCards | orderBy:'toString()'">
   <businesscard>{{card}}</businesscard>
</div>