I have started with angular 2 and I have found it interesting. But from past few days am stuck with something and I need someone to help me out.
Scenario :
Am building a select box with checkbox in a hierarchical structure.
A
|---A1
|---A2
|---A2.1
|---A2.2
|.....
|.....
So the web service will return this data structure in json format. hence I won't be aware of number of hierarchical children it will have
Currently what I have done is:
@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 ]
})
So what I'm doing is I'm checking if data has child then it will repeat the selector again. So this brings hierarchical structure of select box.
But the problem is I have to repeat only the template, currently it is repeating class along with the template, so this is making select all, deselect all, parent - child selection operation difficult.
I thought that <template>
would solve my issue, but no.
Am breaking my head from past two days to solve this but am just getting negative response every time.