I have a tree structure. Jsbin here
in the directive
scope.add_child_task = function() { scope.add_task(scope.path,"child of " + scope.member.name); if (!scope.has_children) { scope.add_children_element(); scope.has_children = true; } };
in the controller
$scope.add_task = function(to,name) { DataFactory.add_task(to,name); };
factory finds the correct position and adds node.
When adding a child node to nodes with existing children, it adds two children, and I donβt understand why.
Thanks.
EDIT I can lose has_children and it still gives the same result
updated jsbin
Member link functin
link: function (scope, element, attrs) { element.append("<collection></collection>"); $compile(element.contents())(scope); scope.get_path = function() { var temp = scope.$parent.get_path(); temp.push(scope.member.name); return temp; }; scope.path = scope.get_path(); scope.add_child_task = function() { scope.add_task(scope.path,"child of " + scope.member.name); }; }
EDIT 2 Dropped the for loops too - just exchanging links, there was nothing left but a function executed twice!
updated jsbin
javascript angularjs
haki
source share