8.1. 排序 orderBy


    orderBy 是一个排序用的过滤器标签。它可以像 sort 函数那样支持一个排序函数,也可以简单地指定一个属性名进行操作:

    1. <div ng-controller="TestCtrl">
      {{ data | orderBy: 'age' }} <br />
      {{ data | orderBy: '-age' }} <br />
      {{ data | orderBy: '-age' | limitTo: 2 }} <br />
      {{ data | orderBy: ['-age', 'name'] }} <br />
      </div>


      <script type="text/javascript">
      var TestCtrl = function($scope){
      $scope.data = [
      {name: 'B', age: 4},
      {name: 'A', age: 1},
      {name: 'D', age: 3},
      {name: 'C', age: 3},
      ];
      }

      angular.bootstrap(document.documentElement);
      </script>