D
D
Dmitry Shvalyov2015-03-05 14:24:02
JavaScript
Dmitry Shvalyov, 2015-03-05 14:24:02

Angular-recursion how to add nesting count count?

There is a service that outputs nested directives: https://github.com/marklagendijk/angular-recursion
How to modify the service itself or a directive based on it in order to get a nesting counter?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TekVanDo, 2015-03-05
@dshster

the easiest way to pass the nesting level as an attribute. more or less like this:

angular.module('myModule', ['RecursionHelper']).directive("tree", function(RecursionHelper) {
    return {
        restrict: "E",
        scope: {family: '=', level='@'},
        template: 
        '<p>{{ family.name }}{{test }}</p>'+
            '<ul>' + 
                '<li ng-repeat="child in family.children">' + 
                    '<tree family="child" level="{{(level)?level + 1: 1}}"></tree>' +
                '</li>' +
            '</ul>',
        compile: function(element) {
            return RecursionHelper.compile(element, function(scope, iElement, iAttrs, controller, transcludeFn){
            });
        }
    };
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question