使用具有角度的多个表行的ng-if

时间:2014-09-20 20:56:04

标签: angularjs

现在我有以下html:

<body ng-controller="defaultCtrl">
<table>
<thead>
  <tr>
    <th>Default</th>
    <th ng-if="c">A</th>
    <th ng-if="c">B</th>
    <th ng-if="c">C</th>
    <th ng-if="c">D</th>
  </tr>
</thead>
</table>
</body>

如果我的defaultCtrl中存在$ scope.c,我希望A,B,C,D显示为表头。

如何分组ng-if而不是重复4次?

当我尝试将四个元素放在div或span中时,我收到一条错误消息,说我正在调用voodoo模式。

1 个答案:

答案 0 :(得分:2)

嗯,你绝对可以这样做

<th ng-if="c" ng-repeat="x in ['A', 'B', 'C', 'D']">{{x}}</th>