An Angular service which helps with creating recursive directives.
npm install angular-recursionbower install angular-recursion --save or npm install angular-recursion --save.
bower_components/angular-recursion/angular-recursion.min.js.
RecursionHelper module as a dependency.
RecursionHelper service and use it.
RecursionHelper service into your directive, and use it in the compile function, as shown in the example below. The example is also available as a Plunker, so you can see it running.
javascript
angular.module('myModule', ['RecursionHelper']).directive("tree", function(RecursionHelper) {
return {
restrict: "E",
scope: {family: '='},
template:
'{{ family.name }}{{test }}
'+
'' +
'- ' +
' ' +
' ' +
'
',
compile: function(element) {
return RecursionHelper.compile(element, function(scope, iElement, iAttrs, controller, transcludeFn){
// Define your normal link function here.
// Alternative: instead of passing a function,
// you can also pass an object with
// a 'pre'- and 'post'-link function.
});
}
};
});
``