ngRepeat中的等于什么?

时间:2016-04-20 09:52:50

标签: javascript angularjs

append属性值中的等于是什么意思?

ng-repeat

而不是:

<li ng-repeat="person in people = (people | orderBy: firstname)">

我看不到任何在ngRepeat文档中解释其用法的例子。

2 个答案:

答案 0 :(得分:8)

计算过滤了多少对象非常有用,例如

function People($scope) {
  $scope.people = [{
    firstname: 'a'
  }, {
    firstname: 'c'
  }, {
    firstname: 'b'
  }, {
    firstname: 'c'
  }]
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app ng-controller="People">
  <ul>
    <li ng-repeat="person in filteredPeople = (people | filter: 'c')">{{person.firstname}}</li>
  </ul>
  Total filtered: {{ filteredPeople.length }}
</div>

答案 1 :(得分:-2)

@Krzysztof - 没有要求&#34; =&#34;运算符用于显示已过滤的对象数。它可以在没有它的情况下完成。所以,你完全错了。

<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl"> 
    <p ng-repeat="x in people | orderBy: 'age'">{{x.name}},{{x.age}}</p> 
    <p>Total Filtered: {{people.length}}</p>
<script>
//Module declaration
var app = angular.module('myApp',[]);
//controller declaration
app.controller('myCtrl',function($scope,$timeout){
    $scope.people = [{name:"Peter",age:15},{name:"Julie",age:28},{name:"Roger",age:17}];

});
</script>

</body> 
</html>