Angular2 choose template dynamically according to service response

て烟熏妆下的殇ゞ 提交于 2019-12-03 12:35:51
Günter Zöchbauer

If you have a limited set of possible templates then *ngIf or *ngSwitch is a good approach. It allows you to use [] and () bindings between parent and child.

If you have a set of templates that are statically unknown and for example provided by a parameter then *ngIf doesn't work. Then ViewContainerRef.createComponent() (replaces DynamicComponentLoader) is the right approach. For an example see Angular 2 dynamic tabs with user-click chosen components

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