I have a tree structure which requires a different set of styling for each level in three tree. Therefore I need some way of keeping track of which level an item is in, so I thought that if there is some way to set a unique ID for an ng-repeat
(NOT the items inside) dynamically, I could easily perform some maths to give the correct stylings inline.
Now I got a recursive tree structure using three files; a wrapper, a new level and a branch (which is the same as a new level). treeWrapper
and treeLevel
is directive which uses these templates.
I've performed an ng-include
inside the tree-branch.html
file in order to make it recursive. The first ng-include
inside tree-level.html
is just to "kickstart" the recursiveness.
So my question is simply how to set an id for each ng-repeat
in the tree? Is this even possible?
tree-wrapper.html
:
<div class="tree-wrapper">
<tree-level ctrl="ctrl" tree="tree"></tree-level>
</div>
tree-level.html
:
<ul class="tree-list">
<li class="tree-item" ng-repeat="branch in tree track by $index"
ng-include="'/app/views/components/tree/tree-branch.html'"></li>
</ul>
tree-branch.html
:
<div ng-click="ctrl.toggleBranch(branch)" ng-bind="branch.name"></div>
<ul class="tree-list" ng-if="branch.branches">
<li class="tree-item" style="padding-left: {{$index * 5}}" ng-repeat="branch in branch.branches"
ng-include="'/app/views/components/tree/tree-branch.html'"></li>
</ul>