如何根据条件将ng-if与表一起使用来显示td [英] How to use ng-if with table to display td based on the condition

查看:103
本文介绍了如何根据条件将ng-if与表一起使用来显示td的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考DIV中有关ng-if的早期文章作为参考,请参见此处提供的链接::

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

尝试:: 1

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>

尝试:: 2

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应该适用于您的 try :: 1 .这是小提琴的工作示例

ng-if should work for your try::1. Here is the fiddle working example

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

这篇关于如何根据条件将ng-if与表一起使用来显示td的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆