Given an Angular directive with the following DOM API:
<my-tree>
<my-tree-item>First</my-tree-item>
<my-tree-item>Second</my-tree-item>
<my-tree-item>Third</my-tree-item>
<my-tree-group>
A group
<my-tree-item>Forth</my-tree-item>
<my-tree-item>Fifth</my-tree-item>
<my-tree-item>Sixth</my-tree-item>
</my-tree-group>
</my-tree>
How can I create something like this with a template and the following data structure:
[
{
name: 'First'
},
{
name: 'Second'
},
{
name: 'Third'
},
{
name: 'A group',
children: [
{
name: 'Forth'
},
{
name: 'Fifth'
},
{
name: 'Sixth'
}
]
}
]
The real data structure may continue down to any depth.
ng-repeat and ng-switch seem needed but require or leave behind extra DOM nodes. For example what should ng-repeat be put on since the item can be 1 of 2 types. When using ng-switch it seemed to help by using it as an element, but that leaves a ng-switch in the DOM.
I considered merging my-tree-item and my-tree-group, but having separate directives seems to make sense as my-tree-group would have extra options that don't apply to regular items.
Is there a way to use Angular to create this exact structure without extra nodes?
Is there a better way to deal with this?
replace:truein directive so no extra nodes exist - charlietfl