Angular2-递归HTML而不制作新组件? [英] Angular2 - recursive html without making a new component?
本文介绍了Angular2-递归HTML而不制作新组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在角度1中,我可以执行以下操作:
In angular 1 I was able to do something like:
<script type="text/ng-template" id="commentView.html">
<div>
<div style="float: left; position: absolute;" ng-style="comment.displayPercent">
</div>
</script>
<script type="text/ng-template" id="commentReplies.html">
<div>
<div class="commentChildBoxStyle" ng-hide="comment.hideComment">
<div style="min-width: 250px;">
<div ng-repeat="comment in comment.replies" ng-include="'commentReplies.html'"></div>
</div>
</div>
</div>
</script>
我意识到我可以在Angular2中递归地调用组件及其模板,但是有没有办法仅递归地构建HTML?这种逻辑似乎更适合于父组件而不是一系列子组件.
I realize I can recursively call a component along with it's template in Angular2, but is there a way to recursively build HTML only? The logic seems like it would fit better with the parent component rather than with a series of child components.
推荐答案
在Angular中肯定只有html
解决方案:
There certainly is a html
only solution in Angular:
<h1>Angular 2 Recursive List</h1>
<ul>
<ng-template #recursiveList let-list>
<li *ngFor="let item of list">
{{item.title}}
<ul *ngIf="item.children.length > 0">
<ng-container *ngTemplateOutlet="recursiveList; context:{ $implicit: item.children }"></ng-container>
</ul>
</li>
</ng-template>
<ng-container *ngTemplateOutlet="recursiveList; context:{ $implicit: list }"></ng-container>
</ul>
这是要点.
这篇关于Angular2-递归HTML而不制作新组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文