ORDERBY:' ' ,在angularjs不工作,错误是什么?

时间:2014-09-25 04:18:36

标签: angularjs filter angularjs-orderby

我正在尝试使用orderBy:names对数组进行排序,但它不起作用,有人可以告诉我我在哪里做错了吗?

<body data-ng-app="app" data-ng-controller="controller1" >
  <div class="container">
    <div class="row">
        <input type="text" ng-model="searchbox" />
        <li ng-repeat="name in names|filter:searchbox|orderBy:'names'">
            {{name}}
        </li>
    </div>
  </div>  

  <script type="text/javascript">
    var app=angular.module('app', []).controller('controller1', ['$scope', function($scope){

      $scope.names=['david', 'shreya', 'ankit'];

    }]);
  </script>

</body>

1 个答案:

答案 0 :(得分:2)

您可以通过toString()方法进行排序。见:How to make orderby filter work on array of strings?。从那个答案:

<ul ng-repeat="strVal in arrVal | orderBy:'toString()' | filter:searchText">