[英]ng-if inside ng-repeat always returning true
I am creating a table with data from the Premier League. 我正在使用英超联赛的数据创建表格。 I am trying to use
ng-if
to check if the home team won and if so add a cell saying "Home team won" 我正在尝试使用
ng-if
检查主队是否获胜,如果是,请添加一个单元格,说“主队获胜”
HTML HTML
<div ng-if="data.full_time_result: === 'H'">
<td>Home Team Won!</td>
</div>
However this is adding the "Home Team Won!" 但是,这增加了“主队获胜!” to every row even when the full_time_result isn't 'H'.
甚至在full_time_result不是'H'的情况下也可以。
Here is a link to the plnkr . 这是到plnkr的链接。
Also, what would be the recommend way to achieve this functionality? 另外,实现此功能的推荐方法是什么? Having lots of
ng-if
blocks probably isn't the best way to go about this. 拥有大量
ng-if
块可能不是解决此问题的最佳方法。
You can not have div
inside table element tr
directly, it would make an invalid html. 您不能在表元素
tr
直接包含div
,它会使html无效。 To make it working you could wrap that div
in td
tag. 为了使其正常工作,您可以将该
div
包装在td
标签中。
Markup 标记
<td>
<div ng-if="data.full_time_result === 'H'">Home Team Won!</div>
</td>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.