简体   繁体   English

递归模板Angular2

[英]Recursive template Angular2

How can I do recursive template with Angular 2 without ng-include. 我如何在没有ng-include的情况下使用Angular 2进行递归模板。 I don't understand why Angular 2 won't include this skill... 我不明白为什么Angular 2不会包含这项技能...

HTML: 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: 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' } ]; }); 

Use ngFor instead of ng-repeat in Angular2. 在Angular2中使用ngFor代替ng-repeat。

https://angular.io/docs/ts/latest/api/common/NgFor-directive.html https://angular.io/docs/ts/latest/api/common/NgFor-directive.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM