如何将带有 tr 标签的 ng-if 与 ng-repeat 一起使用?

How to use ng-if with tr tag along with ng-repeat?

有人可以帮我解决这个问题吗?下面是我的代码和问题的解释。

<table>
 <thead>
   <tr>
     <th>Icon</th>
     <th>Name</th>
     <th>Details</th>
   </tr>
 </thead>

 <tbody ng-repeat="category in editor.categories">
    <tr>
      <th>{{category.categoryName}}</th>
    </tr>
    <tr ng-repeat="feature in category.features"> // Question?
       <td>{{feature.iconImg}}</td>
       <td>{{feature.featureName}}</td>
       <td>{{feature.details}}</td>
     </tr>
     <tr ng-if="feature.id==1"> // condition 1
     </tr>
     <tr ng-if="feature.id==2"> // condition 2
     </tr>
  </tbody>
</table>

现在,让我解释一下这个问题。我有一组类别。每个类别作为一组特征。

现在我的问题是,如何根据ng-if条件显示每个类别的这些特征。即,仅当 feature.id==1 时才应显示条件 1 的 <tr>,并且仅当 feature.id==2.

时才应显示条件 2 中的 <tr>

问。如何根据不同的条件包含我的 ng-if 条件?

非常感谢您的帮助。

在一个标签中同时使用 ng-if 和 ng-repeat:

<tr ng-repeat="feature in features"
    ng-if="feature.id === 1" >
</tr>

或者,如果你想有条件地显示一些模板,你可以使用 ng-switch 例如:

<tr
    ng-repeat="feature in features"
    ng-switch="feature.id" >
    <span ng-switch-when="1"></span>
    <span ng-switch-when="2"></span>
</tr>

检查 ng-switch 和 ng-switch-when

https://docs.angularjs.org/api/ng/directive/ngSwitch

此致