【发布时间】:2018-06-26 22:29:51
【问题描述】:
我有一个 component1 选择器,我称之为“app-component1”。
@Component({
selector: 'app-component1',
templateUrl: './test-widget.component.html',
styleUrls: ['./test-widget.component.scss'] })
所以调用这个组件的html我通常使用:
<app-component1></app-component1>
而且效果很好。
现在从另一个组件 2 我有以下变量:
variableToBind = "<app-component1></app-component1>";
在组件 2 的 html 中,我使用了以下内容:
<div [innerHtml]="varibableToBind"></div>
html 代码绑定不起作用。是否有可能帮助我理解原因并可能帮助我找到另一种选择?
【问题讨论】:
-
为什么你使用
variableToBind而不是直接在你的模板中放入<app-component1></app-component1>?如果你想根据条件选择不同的组件,路由或者*ngIf可以替代吗?
标签: html angular data-binding innerhtml