I have a requirement to create a horizontal binary tree structure that's not like the typical nested <ul /> I see using the ng-repeat directive.
How do I use ng-include and either pass it nested objects or somehow get the nested objects that I need?
Here's the code:
<div id="tree-container" ng-controller="CommentController">
<ul class="root-tree" id="current-tree">
<li class="root node">
<div class="feed">
<div class="comment">{{data.comment}}</div>
</div>
</li>
<li class="root-children">
<ul class="tree" ng-include="'tree'"></ul>
</li>
</ul>
</div>
<script>
app.controller("CommentController", ["$scope", function ($scope) {
$scope.data = {
comments: "blah",
leftChildren: {
comments: ["blah", "blah", "blah"],
leftChildren: { comments: ["blah", "blah", "blah"] },
rightChildren: { comments: ["blah", "blah", "blah"] }
},
rightChildren: { comments: ["blah", "blah", "blah"] }
};
)]);
</script>
<script type="text/ng-template" id="tree">
<li class="node">
<div class="feed">
<div class="comment" ng-repeat="comment in data.leftChildren">{{comment.comment}}</div>
</div>
</li>
<li class="node">
<div class="feed">
<div class="comment" ng-repeat="comment in data.rightChildren">{{comment.comment}}</div>
</div>
</li>
<li class="left-children">
<ul class="tree" ng-include="'tree'"></ul>
</li>
<li class="right-children">
<ul class="tree" ng-include="'tree'"></ul>
</li>
</script>
You can see in the #tree template I have 2 ng-include directives. I would like the $scope for each nested ng-include to use the next level down in the hierarchy on $scope.data, which would be leftChildren and rightChildren.
In other words I basically want the same effect ng-repeat has when calling nested arrays in the $scope.
Hopefully this all makes sense :)
