Angular: Empty Fiddle
http://angularjs.org/
by imagio
HTML
<pre>
<tree val="['a','b',['c1','c2',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a',['a']]]]]]]]]]]]]]]]]]]]]"></tree>
</pre>
CSS
div{
margin-left:10px;
}
JavaScript
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.name = 'Superhero';
}
angular.module('components', [])
.filter('ifarray', function() {
return function(input) {
return $.isArray(input)?input:[];
}
})
.directive('tree', function($compile) {
return {
restrict: 'E',
terminal: true,
scope: {val:'='},
link: function(scope, element, attrs) {
if (angular.isArray(scope.val)) {
element.append('<div>+ <div ng-repeat="item in val"><tree val="item"></tree></div></div>');
} else {
element.append(' - {{val}}');
}
$compile(element.contents())(scope.$new());
} }
});
angular.module('myApp', ['components']);