Angular2 - Dynamic components in content received by API

后端 未结 3 632
礼貌的吻别
礼貌的吻别 2021-01-22 17:04

I have a component . The content for this component is received by API and it contains another components .

The question is, how to render the child component. When I pu

3条回答
  •  礼貌的吻别
    2021-01-22 17:41

    Even when you use the safeHtml pipe mentioned in @laser's answer, Angular doesn't process HTML added using innerHTML. It is just added as HTML and not processed any furter - no components or directives are created, no data binding or event binding will happen.

    What you can do is to create a component at runtime with your HTML as template content and then add this component dynamically using ViewContainerRef.createComponent() and resolveComponentFactory

    See also Equivalent of $compile in Angular 2

提交回复
热议问题