Recently, I delved into the world of angular 2 and found it to be quite fascinating. However, I'm currently facing a roadblock and could really use some assistance.
The scenario is as follows:
I am working on creating a select box with checkboxes in a hierarchical structure.
A
|---A1
|---A2
|---A2.1
|---A2.2
|.....
|.....
The data structure will be returned by a web service in JSON format, so the number of hierarchical children is unknown upfront.
Here's what I've done so far:
@Component({
selector: 'tree-view',
template: `<ul>
<li *ngFor="let items of data">
<a href="javascript:void(0);"
(click)="toggleMultiSelect($event,[items])">
<input type="checkbox" name="{{items.name}}"
[checked]="getChecked(items.id)"
id="{{items.id}}">
<label [attr.for]="items.id" class="custom-unchecked">{{items.name}}</label>
</a>
<tree-view
*ngIf="items.children && items.children.size > 0"
(isSelected)="resultChild($event)"
[data]="items.children"></tree-view>
</li>
</ul>`,
directives: [ MultiHierarchyTreeViewComponent ]
})
Currently, I repeat the selector when there are child elements in the data, resulting in a hierarchical structure for the select box. However, this approach makes select all, deselect all, parent-child selection operations challenging due to the repetition of the class.
I initially thought using <template>
would resolve the issue, but unfortunately, it did not.
I've been trying to solve this puzzle for the past couple of days, but every attempt seems to lead to a dead end.