Angular 指令不接收组件在 ngOnDestroy 方法中所做的更改

Angular Directive doesn't receive changes from component made in ngOnDestroy method

组件被销毁后出现意外指令行为。

指令未在组件的 ngOnDestroy 方法中进行更改

组件:

export class InfoButtonComponent implements OnDestroy {
    display = false;

    justMethod() {
      this.display = true | false; // (whatever) works fine, directive recevied that display was changed
    }

    ngOnDestroy(): void {
      this.display = false; // directive doesn't handle it
      this.cdr.detectChanges();
    }
}

<div
    [show]="display"
  >1</div>

指令:

export class TooltipDirective implements OnChanges {
  @Input() show = false;
  ngOnChanges(changes: SimpleChanges): void {
    // get changes from component made in other methods
    // doesn't get changes made in ngOnDestroy method
  }
}

似乎与 ngOnDestroy():

的文档说明相符

Called immediately before Angular destroys the directive or component.

我会把重点放在“立即”上,不希望之后 运行 进行另一轮变更检测。

不清楚你试图完成什么,但听起来像是 hack。