Angularjs 如何使用带有tr标签的ng if和ng repeat?
有人能帮我吗?下面是我的代码和问题说明Angularjs 如何使用带有tr标签的ng if和ng repeat?,angularjs,angularjs-ng-repeat,angularjs-ng-if,Angularjs,Angularjs Ng Repeat,Angularjs Ng If,有人能帮我吗?下面是我的代码和问题说明 <table> <thead> <tr> <th>Icon</th> <th>Name</th> <th>Details</th> </tr> </thead> <tbody ng-repeat="category in editor.categories">
<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>
偶像
名称
细节
{{category.categoryName}
//问题?
{{feature.iconImg}
{{feature.featureName}
{{feature.details}}
//条件1
//条件2
现在,让我解释一下这个问题。我有一组类别。每个类别都是一组功能
现在我的问题是,如何根据ng if
条件显示每个类别的这些功能。i、 例如,条件1下的
仅当特征.id==1时显示,条件2下的特征.id==2时也应显示
问:如何根据不同的条件包括我的ng if条件?
非常感谢您的帮助。在一个标签中同时使用ng if和ng repeat:
<tr ng-repeat="feature in features"
ng-if="feature.id === 1" >
</tr>
或者,如果要有条件地显示某些模板,可以使用ng开关,例如:
<tr
ng-repeat="feature in features"
ng-switch="feature.id" >
<span ng-switch-when="1"></span>
<span ng-switch-when="2"></span>
</tr>
检查ng开关和ng开关
注意看起来ng repeat start和ng repeat end更适合您的html结构。这会导致第二个示例中的实际呈现到DOM中吗?如果是这样的话,这是有效的HTML(在没有td的tr中直接有一个跨度?)