簡體   English   中英

遞歸模板Angular2

[英]Recursive template Angular2

我如何在沒有ng-include的情況下使用Angular 2進行遞歸模板。 我不明白為什么Angular 2不會包含這項技能...

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

在Angular2中使用ngFor代替ng-repeat。

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