Javascript Angular 2动态创建html标记

Javascript Angular 2动态创建html标记,javascript,angular,typescript,Javascript,Angular,Typescript,有没有办法在组件模板中动态创建html标记 像这样的 template:`<{{custom_tag}} [info]="info"></{{custom_tag}}>` ... this.custom_tag="example"; this.info={}; <example info="..."></example> 模板:`` ... 这个.custom_tag=“example”; this.info={}; 生成的html如下所示

有没有办法在组件模板中动态创建html标记

像这样的

template:`<{{custom_tag}} [info]="info"></{{custom_tag}}>`
...
this.custom_tag="example";
this.info={};
<example info="..."></example>
模板:``
...
这个.custom_tag=“example”;
this.info={};
生成的html如下所示

template:`<{{custom_tag}} [info]="info"></{{custom_tag}}>`
...
this.custom_tag="example";
this.info={};
<example info="..."></example>

我也遇到了同样的问题,我用一个指令来替换标签:


很抱歉耽搁了您的时间,但我要添加我的回复:

创建一个新组件,现在您可以在任何需要的地方使用组件选择器标记本身

喜欢

将选择器用作:

<app-example></app-example>

将参数传递给新组件,如下所示:

 <app-example [param]="abc"></app-example>


需要使用@input()属性使用相同的标识符“param”标识此输入参数。

通过自定义html标记,您实际上是指组件吗?这个问题是关于动态组件的吗?@PeterMatisko是的。该标记将是解决类似问题的组件。请检查我的问题和答案,这可能会有所帮助:您需要使用编译器来动态添加组件。