我有一张结果表:
<tr ng-repeat="result in results">
<td>{{result.foo}}</td>
<td ng-if="result.bar == '1'">it's One!</td>
<td ng-if="result.bar != '1'">it's not One! is {{result.bar}}</td>
</tr>
显示3,为什么ng-if不起作用?
结果在范围内正确设置,因为“它不是一个!是5显示OK”
答案 0 :(得分:1)
这是一个版本问题。
html示例:
Click me: <input type="checkbox" ng-model="checked" ng-init="checked=true" /><br/>
Show when checked:
<span ng-if="checked" class="animate-if">
I'm removed when the checkbox is unchecked.
</span>
适用于:
<script src="http://code.angularjs.org/1.2.12/angular.min.js"></script>
但不是:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
答案 1 :(得分:0)
不确定为什么它不起作用,但你可以尝试另一种方法:
<tr ng-repeat="result in results">
<td>{{result.foo}}</td>
<ng-switch on="result.bar">
<td ng-switch-when="1">it's One!</td>
<td ng-switch-when="2">it's not One! is {{result.bar}}</td>
</ng-switch>
</tr>