I'm currently working with a list in Angular 2 and utilizing recursive rendering techniques as shown in this tutorial. While displaying the list as an unordered list works perfectly fine, I wanted to experiment with a collapsible list structure similar to the one demonstrated in this example. However, I encountered difficulties in maintaining the hierarchical structure of the items when attempting to implement the collapsible list.
Code for displaying as an unordered list:
<ul *ngIf="items.length">
<li *ngFor="let item of items">
{{item.name}}
<tree-view *ngIf="item[key]?.length" [key]="key" [data]="item[key]"></tree-view>
</li>
</ul>
Result:
https://i.sstatic.net/QQX6M.png
Code for displaying as a collapsible list:
<div class="list-group collapse" id="item-1" *ngFor="let item of items">
<a href="#item-1-1" class="list-group-item list-group-item-warning" data-toggle="collapse">
<i class="glyphicon glyphicon-chevron-right"></i><strong>{{item.name}}</strong>
</a>
<div class="list-group collapse" id="item-1-1">
<tree-view *ngIf="item[key]?.length" [key]="key" [data]="item[key]"></tree-view>
</div>
</div>
Result: https://i.sstatic.net/tjC4f.png
.
Styles:
.just-padding {
padding: 15px;
}
.list-group.list-group-root {
padding: 0;
overflow: hidden;
}
.list-group.list-group-root .list-group {
margin-bottom: 0;
}
.list-group.list-group-root .list-group-item {
border-radius: 0;
border-width: 1px 0 0 0;
}
.list-group.list-group-root > .list-group-item:first-child {
border-top-width: 0;
}
.list-group.list-group-root > .list-group > .list-group-item {
padding-left: 30px;
}
.list-group.list-group-root > .list-group > .list-group > .list-group-item {
padding-left: 45px;
}
.list-group-item .glyphicon {
margin-right: 5px;
}
What modifications should be made to the HTML code to maintain the hierarchical display of items?