2016-03-31 10 views
0

Wie kann ich rekursive Vorlage mit Angular 2 ohne ng-include tun. Ich verstehe nicht, warum Angular 2 nicht diese Fähigkeit schließen ...Rekursive Vorlage 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' 
 
    } 
 
    ]; 
 
});

+0

Erstellen Sie einfach eine Komponente und tun Sie es darin. Was ist dein Zweck dabei? –

+0

Sie können dazu die Komponente in der Komponente verwenden. Verwenden Sie ngFor als ng-repeat und "call" -Komponente mit Details. – IceManSpy

+0

Ich finde eine Lösung auf http://jilles.me/ng-repeat-in-angular2-ng-for/ – vivi94

Antwort

Verwandte Themen