angular - 在 Angular 9 中,我应该使用什么来代替 @HostBinding ("@grow")?

标签 angular angular2-hostbinding

我有这个指令,我用它来动画组件高度的变化。但是自从我们从 Angular 8 更新到 9 后,它看起来几乎不再支持 hostPropertyName @grow。这是指令:

import {
  Directive,
  OnChanges,
  Input,
  ElementRef,
  HostBinding
} from "@angular/core";

@Directive({
  selector: "[smoothHeight]",
  host: { "[style.display]": '"block"' }
})
export class SmoothHeightDirective implements OnChanges {
  @Input()
  smoothHeight;
  pulse: boolean;
  startHeight: number;

  constructor(private element: ElementRef) {}

  @HostBinding("@grow")
  get grow() {
    return { value: this.pulse, params: { startHeight: this.startHeight } };
  }

  setStartHeight() {
    this.startHeight = this.element.nativeElement.clientHeight;
  }

  ngOnChanges() {
    this.setStartHeight();
    this.pulse = !this.pulse;
  }
}

Chrome 抛出以下错误:

core.js:6185 错误类型错误:无法读取 null 的属性“11”

Safari 想出了这个:

TypeError:null 不是一个对象(正在评估“componentLView[RENDERER]”)

和火狐:

错误类型错误:“componentLView 为空”

关于我做错了什么以及如何解决它有什么建议吗?

最佳答案

看起来问题出在 Angular (9.1.2) 上,更新 Angular 后它似乎可以工作。

关于angular - 在 Angular 9 中,我应该使用什么来代替 @HostBinding ("@grow")?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61080712/

相关文章:

angular - onbeforeunload 确认对话框在使用 angular2 @HostListener 时不显示

html - ionic 输入的 Ionic 3 键盘问题

Angular Material Datepicker 以编程方式设置最小值

angular - 我可以为@HostBinding 装饰器设置什么参数?

css - HostBinding 未绑定(bind)到 CSS 变量

css - 如何向调用的 Angular 组件本身添加一个类?

javascript - 将 NG2 指令降级为 AngularJS

java - 如何从 Angular 2 应用程序执行驻留在服务器上的 Java 代码?

javascript - 不确定如何在包含 Promises 的方法中填充数组