2017-02-27 116 views
0

有没有办法在组件模板中动态创建html标签?Angular 2动态创建html标签

像这样的事情

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

生成的HTML将是这样的

<example info="..."></example> 
+0

通过定制html标签,你实际上是指一个组件?这是关于动态组件的问题吗? –

+0

@PeterMatisko是的。该标签将是一个组件 –

+1

我正在解决类似的问题。请检查我的问题和答案,这可能会有所帮助:http://stackoverflow.com/questions/42215288/angular2-dynamic-components-in-content-received-by-api 您需要使用编译器来动态添加组件。 –

回答