2016-03-31 6 views
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' 
 
    } 
 
    ]; 
 
});

+0

コンポーネントを作成してその中で実行してください。これを行う上であなたのポイントは何ですか? –

+0

コンポーネントでコンポーネントを使用してこれを行うことができます。 ng-repeatをng-repeatとして使用し、詳細を「呼び出し」コンポーネントに追加します。 – IceManSpy

+0

http://jilles.me/ng-repeat-in-angular2-ng-for/に解決策があります – vivi94

答えて