Dmitry Shvalyov2015-03-05 14:24:02
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)
TekVanDo, 2015-03-05

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='@'},
        '<p>{{ family.name }}{{test }}</p>'+
            '<ul>' + 
                '<li ng-repeat="child in family.children">' + 
                    '<tree family="child" level="{{(level)?level + 1: 1}}"></tree>' +
                '</li>' +
        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