angular-recursion
v1.0.5
Published
An Angular service which helps with creating recursive directives.
Downloads
15,888
Maintainers
Readme
angular-recursion
A service which makes it easy possible to have recursive Angular directives.
Why
When an Angular directive calls itself, Angular gets into an endless loop. This service provides the logic needed to work around this.
Installation
bower install angular-recursion --save
ornpm install angular-recursion --save
.- Include
bower_components/angular-recursion/angular-recursion.min.js
. - Add the
RecursionHelper
module as a dependency. - Inject the
RecursionHelper
service and use it.
Usage
Inject the 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.
angular.module('myModule', ['RecursionHelper']).directive("tree", function(RecursionHelper) {
return {
restrict: "E",
scope: {family: '='},
template:
'<p>{{ family.name }}{{test }}</p>'+
'<ul>' +
'<li ng-repeat="child in family.children">' +
'<tree family="child"></tree>' +
'</li>' +
'</ul>',
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.
});
}
};
});