0
ng-includeなしで角2の再帰テンプレートを作成するにはどうしたらいいですか?再帰テンプレートAngular2
<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'
}
];
});
コンポーネントを作成してその中で実行してください。これを行う上であなたのポイントは何ですか? –
コンポーネントでコンポーネントを使用してこれを行うことができます。 ng-repeatをng-repeatとして使用し、詳細を「呼び出し」コンポーネントに追加します。 – IceManSpy
http://jilles.me/ng-repeat-in-angular2-ng-for/に解決策があります – vivi94