【发布时间】:2018-08-28 03:12:44
【问题描述】:
我遇到了以下Plunker 来动态添加和删除组件。 根据上面的链接和许多其他 SO 帖子,我知道如何访问 Input 和 Output 属性:
this.compRef.instance.someProperty = 'someValue';
this.compRef.instance.someOutput.subscribe(val => doSomething());
而且我还有一个指令“appFont”。
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[appFont]'
})
export class HighlightDirective {
constructor(el: ElementRef) {
el.nativeElement.style.font = 'Calibri';
}
}
如何将这个“appFont”指令添加到新的动态创建的组件中?
【问题讨论】:
标签: angular angular-directive angular-components