84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
这样写是对的
<li ng-repeat="(x, y) in item" ng-if="x!='a'"></li>
这样写就是输出全部的,ng-if并没有执行
<li ng-repeat="(x, y) in item" ng-if="test()"></li> ... $scope.test = function(){ return "x!='a'" }
认证高级PHP讲师
第一你没有把x传进去,第二你返回的是一个字符串,字符串永远是对的。这样写再试试:
<li ng-repeat="(x, y) in item" ng-if="test(x)"></li> $scope.test = function(x){ return x!='a'; }
告诉你一个概念, ng-if中的东西叫做angular表达式,angular会对这个表达式进行parse。"x!='a'"其实就是$scope.x != 'a',顺带一提这个$scope是ng-repeat产生的scope。下面的test()当然会变parse成$scope.test()在ngRepeat的scope中没找到方法,所以从父scope中找到了你的方法, 然后你的方法return的是一个字符串, 所以判断永远是true了。
"x!='a'"
$scope.x != 'a'
$scope
ng-repeat
test()
$scope.test()
true
第一你没有把x传进去,第二你返回的是一个字符串,字符串永远是对的。这样写再试试:
告诉你一个概念, ng-if中的东西叫做angular表达式,angular会对这个表达式进行parse。
"x!='a'"
其实就是$scope.x != 'a'
,顺带一提这个$scope
是ng-repeat
产生的scope。下面的
test()
当然会变parse成$scope.test()
在ngRepeat的scope中没找到方法,所以从父scope中找到了你的方法, 然后你的方法return的是一个字符串, 所以判断永远是true
了。