Angular2 choose template dynamically according to service response

前端 未结 1 1634
说谎
说谎 2021-02-14 22:10

I have a component called "Node" which should display a single post, but I have more than a post type and each type has its own view (layout).

So this componen

相关标签:
1条回答
  • 2021-02-14 22:27

    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

    0 讨论(0)
提交回复
热议问题