问题
I need to stop a one set of elements repeated in my angular 7 application.
That set of elements are working with dynamic data.
So I create that set of elements in one component.
But I can't call that component inside of that component.
回答1:
I got a solution for that
<ul>
<li *ngFor='let link of links'>
<ng-container
*ngTemplateOutlet="simpleLink; context:{link:link}">
</ng-container>
</li>
</ul>
<ng-template #simpleLink let-link='link'>
Simple : {{ link.name }}
<ul>
<li *ngFor='let link of link.childLinks'>
<ng-container
*ngTemplateOutlet="simpleLink; context:{link:link}">
</ng-container>
</li>
</ul>
</ng-template>
来源:https://stackoverflow.com/questions/55878988/repeated-elements-with-dynamic-datas-code-optimize-in-angular7