Repeated elements with dynamic datas code optimize in angular7

ぃ、小莉子 提交于 2019-12-26 13:23:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!