【发布时间】:2019-06-20 14:41:23
【问题描述】:
如何在 Angular 中以编程方式构造选择器?
假设我有一个名为 header.component 的父组件,它看起来像这样;
export class ContentHeaderComponent {
@Input() iconName: string;
}
...我正在使用 Angular Feather 向应用程序添加图标,这需要您执行以下操作来创建图标:
<i-chevron-down></i-chevron-down>
在我的标题组件模板中,我想通过父组件将“chevron-down”传递给标签。实际上,我希望在标题组件中做这样的事情:
<i-{{ iconName }}></i-{{ iconName }}>
是否可以在 Angular 中动态构建选择器?
【问题讨论】:
-
我不确定,但您可以尝试
domSanitizer.bypassSecurityTrustHtml方法。this.html = domSanitizer.bypassSecurityTrustHtml(${iconName}>`); -
有趣的想法@epsilon。这不是世界上最安全的事情,但考虑到我只是将它用于图标......让我测试一下。
标签: angular angular-components angular-template