I try to build my menue with n sub menues with AngularJS. this is my scope:
$scope.menu = [
{"type": "folder", "name": "TestFolder1", "subfolder": []},
{"type": "folder", "name": "TestFolder2", "subfolder": [
{"type": "folder", "name": "TestFolder2", "subfolder": [
{"type": "folder", "name": "TestFolder2", "subfolder": []},
{"type": "folder", "name": "TestFolder2", "subfolder": []}
]},
{"type": "folder", "name": "TestFolder2", "subfolder": []}
]},
{"type": "file", "name": "testfile"}
];
this is my directive
codeApp.directive('item', ['$compile', function ($compile) {
return {
restrict: 'E',
replace: true,
scope: {
item: '='
},
template: '<li>'+
'<a id="item"><i class="fa fa-code-fork fa-fw"></i>{{item.name}}</a>'+
'</li>',
link: function($scope, $element) {
if (angular.isArray($scope.item.subfolder) && $scope.item.subfolder.length > 0) {
$element.append('<ul><item ng-repeat="childItem in item.subfolder" item="childItem"></item></ul>');
$compile($element.contents())($scope);
}
}
};
}]);
and my first line is this :
<item ng-repeat="item in menu" item="item"></item>
The menu is created, but only the first level and I'm not sure how the compile function works. How can I achieve that the line is appended after the ?