如何使用ng-if with table根据条件显示td [英] How to use ng-if with table to display td based on the condition
问题描述
参考之前关于 DIV 中 ng-if 的帖子 参考这里给出的链接 :: Ng-If 在 DIV 中,但是当我在 td 上使用 ng-repeat 在表中尝试使用 ng-if 时,它似乎效果不佳.如果我错了,请纠正我 我做了 2 次尝试根据条件显示该列,但没有任何效果.下面我给出了代码供参考.有人可以帮我解决这个问题.如果您需要更多说明,请告知.
HTML
尝试 :: 1
<tr ng-repeat = "评论中的数据"><td ng-if="data.type == 'hootsslllll'">//不同的模板与热门数据</td><td ng-if="data.type == 'story' ">//具有故事数据的不同模板</td><td ng-if="data.type == '文章'">//带有文章数据的不同模板</td></tr>
尝试 :: 2
<tr ng-repeat = "评论中的数据"><div ng-if="data.type == 'hootsslllll'"><td>//不同的模板与 hoot 数据 </td><div ng-if="data.type == '故事'"><td>//具有故事数据的不同模板</td>
<div ng-if="data.type == '文章'"><td>//具有文章数据的不同模板</td>
</tr>
ng-if
应该适用于您的 try::1.这是小提琴工作示例
http://jsfiddle.net/shivaraj/n3xWB/
With reference to the earlier post on ng-if within DIV for reference the link given here :: Ng-If within DIV , however when i tried the same with ng-if inside table with ng-repeat on td it doesn't seems to work well. Correct me if I'm wrong I made 2 tries to display the column based on the condition but none works. Below i have given the code for reference. Could somebody help me on this. Kindly let know if you need more clarification.
HTML
Try :: 1
<table>
<tr ng-repeat = "data in comments">
<td ng-if="data.type == 'hootsslllll' ">
//differnt template with hoot data
</td>
<td ng-if="data.type == 'story' ">
//differnt template with story data
</td>
<td ng-if="data.type == 'article' ">
//differnt template with article data
</td>
</tr>
</table>
Try :: 2
<table>
<tr ng-repeat = "data in comments">
<div ng-if="data.type == 'hootsslllll' ">
<td> //differnt template with hoot data </td>
</div>
<div ng-if="data.type == 'story' ">
<td> //differnt template with story data </td>
</div>
<div ng-if="data.type == 'article' ">
<td> //differnt template with article data </td>
</div>
</tr>
</table>
ng-if
should work for your try::1. Here is the fiddle working example
http://jsfiddle.net/shivaraj/n3xWB/
这篇关于如何使用ng-if with table根据条件显示td的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!