0
如何在没有ng-include的情况下使用Angular 2进行递归模板。我不明白为什么角2将不包括这个技能...递归模板Angular2
HTML:
<div ng-app="app" ng-controller='AppCtrl'>
<script type="text/ng-template" id="categoryTree">
{{ category.title }}
<ul ng-if="category.categories">
<li ng-repeat="category in category.categories" ng-include="'categoryTree'">
</li>
</ul>
</script>
<ul>
<li ng-repeat="category in categories" ng-include="'categoryTree'"></li>
</ul>
JS:
var app = angular.module('app', []);
app.controller('AppCtrl', function ($scope) {
$scope.categories = [
{
title: 'Computers',
categories: [
{
title: 'Laptops',
categories: [
{
title: 'Ultrabooks'
},
{
title: 'Macbooks'
}
]
},
{
title: 'Desktops'
},
{
title: 'Tablets',
categories: [
{
title: 'Apple'
},
{
title: 'Android'
}
]
}
]
},
{
title: 'Printers'
}
];
});
只要创建一个组件,并在里面做。你这样做的意义何在? –
您可以使用组件中的组件来执行此操作。使用ngFor作为ng-repeat和“call”组件的细节。 – IceManSpy
我在http://jilles.me/ng-repeat-in-angular2-ng-for/找到解决方案 – vivi94