一尘不染

如何根据条件使用ng-if和table显示td

angularjs

参考之前关于DIV中ng-if的文章以供参考,这里给出了链接::Ng-If在DIV中,但是当我在ng-repeat表上尝试ng-if并在td上使用ng-repeat时,似乎没有做得好。如果我错了,请纠正我,我根据条件尝试进行2次显示该列,但均无效果。下面我给出了代码以供参考。有人可以帮我这个忙。请告知是否需要进一步说明。

HTML

尝试:: 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>

尝试:: 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>

阅读 570

收藏
2020-07-04

共1个答案

一尘不染

ng-if应该为您工作 try :: 1 。这是小提琴的工作示例

http://jsfiddle.net/shivaraj/n3xWB/

2020-07-04