gpt4 book ai didi

angular - Angular 4 中的 ng-repeat start 和 endwith

转载 作者:太空狗 更新时间:2023-10-29 18:12:39 26 4
gpt4 key购买 nike

我嵌套了 ng-repeat 来构建可折叠网格。需要在 Angular 4 中实现相同的目标。我在 *ngFor 中找不到解决方案。我使用 anuglar js 实现的示例代码。

<table width="100%" class="table-condensed responsive-table">
<tr class="panel-heading bgOrg">
<th class="text-right th-font">&nbsp;</th>
<th class="text-right th-font">VMs</th>
..
</tr>
<tr ng-if="!departments.length" >
<td colspan="15" class="text-center">No records Found</td>
</tr>
<tr ng-repeat-start="department in departments">
<td class="table-white-space">
<div class="handpointer glyphicon glyphicon-chevron-right" data-ng-click="department.show = !department.show;collapse($event)" data-target="#view_{{department.departmentid}}" data-toggle="collapse"
aria-expanded="false"
data-ng-if="department.environment!=null && !department.show">
</div>
<div class="handpointer glyphicon glyphicon-chevron-down" data-ng-click="department.show = !department.show;collapse($event)" data-target="#view_{{department.departmentid}}" data-toggle="collapse"
aria-expanded="false"
data-ng-if="department.environment!=null && department.show">
</div>
<span class="row-label"> <b ng-bind="department.name"></b> </span>
</td>
..
</tr>
<tr ng-repeat-start="item in department.environment" ng-if="department.show">
..
</tr>
<tr ng-repeat-start="cItem in item.vm" ng-if="department.show && item.show">
..
</tr>
<tr ng-repeat="iItem in cItem.storage" ng-if="department.show && item.show && cItem.show">
..
</tr>
<tr ng-repeat-end=""></tr>
<tr ng-repeat-end=""></tr>
<tr ng-repeat-end=""></tr>

如何在angular2中实现相同?

enter image description here

最佳答案

您在 Angular 4 中没有任何 ng-repeat-start 或 end。您可以使用“ng-container”代替它。

<ng-container *ngFor="let depertment of departments">
<!-- Ng-repaet started here -->
<tr *ngFor="let env of department.environments">
<td></td>
</tr>
<!-- Ng-repeat end -->
<tr> --Do something-- </tr>
</ng-container>

<ng-container> to the rescue.
The Angular is a grouping element that doesn't interfere with styles or layout because Angular doesn't put it in the DOM.
For additionally, if you need to pass any value use ngTemplateContext

关于angular - Angular 4 中的 ng-repeat start 和 endwith,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49746738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com