当我使用ng-if时带有标志且列表包含一些值:
<tr ng-if="flag" ng-repeat="x in list1">
{{"print a"}}
<!-- do something -->
</tr>
<tr ng-if="!flag" ng-repeat="x in list2">
{{"print b"}}
<!-- do something -->
</tr>
无论flag是什么,都打印a和b。它应该只根据标志值打印a和b吗?
答案 0 :(得分:0)
你去..
var app = angular.module('myApp',[])
.controller('myCtrl',function($scope){
$scope.flag = true;
$scope.list1 = [10,20,30,40,50];
$scope.list2 = [10,20,30,40,50];
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<table ng-app="myApp" ng-controller="myCtrl">
<tr ng-if="flag" ng-repeat="x in list1">
<td>
{{"print a"}}
</td>
</tr>
<tr ng-if="!flag" ng-repeat="x in list2">
<td>
{{"print b"}}
</td>
</tr>
</table>
&#13;
所以,它确实有效。