I'm looking to display data in a tree structure in a web app. I was hoping to use Angular for this task.
Looks like ng-repeat will allow me to iterate through a list of nodes, but how can I then do nesting when a given node's depth increases?
I tried the following code, but the auto-escaping of the HTML is preventing this from working. Plus, the end ul tag is in the wrong place.
I'm pretty sure that I'm going about this problem entirely the wrong way.
Any ideas?
Have a look at this fiddle
Original: http://jsfiddle.net/brendanowen/uXbn6/8/
Updated: http://jsfiddle.net/animaxf/uXbn6/4779/
This should give you a good idea of how to display a
tree like structure
using angular. It is kind of using recursion in html!Here is an example using a recursive directive: http://jsfiddle.net/n8dPm/ Taken from https://groups.google.com/forum/#!topic/angular/vswXTes_FtM
Yes it definitely possible. The question here probably assumes Angular 1.x, but for future reference I am including an Angular 2 example:
Conceptually all you have to do is create a recursive template:
You then bind a tree object to the template and let Angular work its magic. This concept is obviously applicable to Angular 1.x as well.
Here is a complete example: http://www.syntaxsuccess.com/viewarticle/recursive-treeview-in-angular-2.0
Not complicated.
controller code:
You can try with Angular-Tree-DnD sample with Angular-Ui-Tree, but i edited, compatibility with table, grid, list.
This one seems a bit more complete: https://github.com/dump247/angular.tree