Angularjs。 ng-switch无法在桌面内工作 [英] Angularjs. ng-switch not working inside a table

查看:104
本文介绍了Angularjs。 ng-switch无法在桌面内工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何我可以让ng-switch在桌子内工作吗?表示例不起作用,但ul exampel工作正常。问题是我真的需要表格示例。我使用角度1.07。

Is there anyway I can get ng-switch working inside a table? The table example is not working but the ul exampel just work fine. The problem is that I really need the table example. I am using angular 1.07.

<table>
  <tbody ng-repeat="item in items">

  <tr><td>{{ item.heading }}</td></tr>

  <tr ng-repeat="row in item.fields" ng-switch on="row.nb">

  <div ng-switch-when="01">
    <td>{{ row.nb }}</td>
  </div>

  </tr>

  </tbody>

</table>

<ul ng-repeat="item in items">
  <li ng-repeat="row in item.fields" ng-switch on="row.nb">

  <div ng-switch-when="01">
    {{ row.nb }}
  </div>

  </li>
</ul>


推荐答案

你需要移动 ng-switch-when 到td,否则会忽略它为无效,因为 div 中无效标记TR https://developer.mozilla.org/en-US/docs/Web/HTML/元素/ tr

You need to move the ng-switch-when to the td otherwise it will ignore it as invalid because a div is not valid markup inside a tr. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr

删除div并将其更改为:

Remove the div and change it to:

 <td ng-switch-when="01">{{ row.nb }}</td>

演示: http://plnkr.co/edit/yHkBGekjgGDts8pNtekJ?p=preview

这篇关于Angularjs。 ng-switch无法在桌面内工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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