【发布时间】:2016-03-08 07:08:21
【问题描述】:
我有一个笨蛋:https://plnkr.co/edit/OlLt9XC6cWYnus20ZEaz?p=preview
我有一个 ng-repeat,它调用一个函数并获得 .outcome 的结果,结果是真或假。但是,如果不返回这些值,则默认为 x。
我想做的是对 ng-repeat 值执行 ng-if 以便:
if outcome is true, show icon-true.
if outcome is false, show icon-cross.
if outcome is x, show icon-blank.
HTML:
<div ng-repeat="month in months">
{[{getData(contents[item._id].contentHistory,year,month.n)}]}
<!-- <i class="icon-cross" ng-if="getData(contents[item._id].contentHistory,year,month.n == false"></i>
<i class="icon-true" ng-if="getData(contents[item._id].contentHistory,year,month.n == true"></i>
<i class="icon-blank" ng-if="getData(contents[item._id].contentHistory,year,month.n == x"></i> -->
</div>
【问题讨论】:
-
什么是
x?是字符串吗? -
@mgilson 是的。看看 plunker 中的控制器
-
您需要与
'x'而不是x进行比较,因为它不是变量而是值。并关闭getDatacall 的圆括号。如果那是纠正,代码工作正常。你的样式/图标有问题,我没有深入,尝试使用标签而不是图标。工作。
标签: javascript angularjs angularjs-ng-repeat ng-class angular-ng-if