angularjs - Angular recursive directive with functions -


new angular , trying wrap head around these scopes. want functions inherited infinetly down tree. code below have , works first level, after i'm sort of lost. ideas?

<tree get-branch="getbranch(parent, $event)" show-menu="showmenu(parent)" family="i"></tree>   $scope.getbranch = function (parent, $event) {... $scope.showmenu = function(parent) {...  app.directive("tree", function (recursionhelper) { return {     restrict: "e",     scope: {         getbranch: "&",         showmenu: "&",         family: '='     },     template:         '<a ng-right-click="showmenu({ parent: family })" ng-click="getbranch({parent:family, $event:$event})" >{{ family.alias }}</a>' +         '<ul ng-if="family.iscategory">' +             '<li ng-repeat="child in family.children" ng-class="{category: child.iscategory}">' +                 '<tree get-branch="getbranch({family:family, $event:$event})" show-menu="showmenu({ family: family })" family="child"></tree>' +             '</li>' +         '</ul>',     compile: function (element) {         return recursionhelper.compile(element, function (scope, ielement, iattrs, controller, transcludefn) {             // define normal link function here.             // alternative: instead of passing function,             // can pass object              // 'pre'- , 'post'-link function.         });     } }; }); 

if want function usable anywhere, or value shared anywhere in application think approach wrong. typically should in service or factory. have @ https://docs.angularjs.org/guide/services


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -