I looked up a lot of different answers here but most of them are not accurate. So, I wanted to ask what a good approach would look like to show and hide lists (ul) but only the list which was clicked on via onclick.
I have the following tempplate
<ul *ngIf="children">
<ng-container *ngTemplateOutlet="recursiveListTmpl; context:{ $implicit: children }"></ng-container>
</ul>
<ng-template #recursiveListTmpl let-children>
<li *ngFor="let item of children; let i=index">
{{item.name}}
<ul *ngIf="item.children" class="sublists">
<ng-container *ngTemplateOutlet="recursiveListTmpl; context:{ $implicit: item.children }"></ng-container>
</ul>
</li>
</ng-template>
Children
is an array of objects containing a name and further children.
I tried to bind specific classes for each sublist and then get those element via document.getElementsByClassNames
but it did not work correctly.
Do you have any currently correct approach to tackle my problem? How should I try to toggle those sublists? I really have no idea anymore... My Angular Version is 9.
. Please share a screenshot of your list and sublist
– Dewanshu Jul 02 '20 at 10:14``` sublists are directories and all ```- ``` items represent the files of the directory and it works pretty well. I just have to add a toggle functionality for which I have no approach yet. I could add an extra property but if it is possible, I would like to do it without an extra property.
– Operator Jul 02 '20 at 10:21