Angular:无法使用* ngComponentOutlet为动态创建的内容指定指令

时间:2017-06-10 17:57:54

标签: angular angular-directive dynamically-generated

https://plnkr.co/edit/KrAV2oJWjSDMiqIyqtBi?p=preview

获得了一个创建,编译和注入组件的组件。 我有两个组件,我正在创建foo-bar和foopica-bar。 我已经创建了一个指令ContentEditableDirective,但不知何故看不到该指令。

在加载时,它应调用该指令并将背景颜色黄色添加到本机元素样式。

@Directive({
    selector: '[myHighlight]',

})

export class ContentEditableDirective {

    constructor(el: ElementRef) {
       el.nativeElement.style.backgroundColor = 'yellow';
       console.log(' el.nativeElement.style',  el.nativeElement.style)
    }
     ngAfterContentInit(){
     console.log('calling me again')}
}

0 个答案:

没有答案