0

ホストの ngOnChange が起動すると、ホスト コンポーネントの背景を緑色に点滅させる角度ディレクティブを作成したいと考えています。

viewContainerRef を介してホストの ngOnChange メソッドに (ディレクティブで) アクセスしようとしましたが、見つかりませんでした。

import { Directive, ElementRef, ViewContainerRef } from '@angular/core';

@Directive({
  selector: '[OnChangeBlink]'
})
export class OnChangeBlinkDirective{

  readonly green_color:string = '#27AE60'
  readonly white_color:string = '#FFFFFF'
  element_ref:ElementRef;

  doBlink(color: string):void {

    if(color){
      this.element_ref.nativeElement.style.backgroundColor = this.green_color;
      setTimeout(() => {
        this.element_ref.nativeElement.style.backgroundColor = this.white_color;      
      }, 500);
    }
  }

  constructor(elRef: ElementRef, private vcRef: ViewContainerRef) { 

    this.element_ref = elRef;

    const component = vcRef['_data']['componentView']['component'];

    if (component.hasOwnProperty('ngDoCheck')){//never happens
      console.log(component['ngDoCheck']);
    }
  }
}

ngOnChange メソッドに罰金を科したことはありません。おそらく私のすべてのアプローチが間違っていますか? どうすればできますか?

4

0 に答える 0