【问题标题】:What should I use instead of @HostBinding("@grow") in Angular 9?我应该在 Angular 9 中使用什么来代替 @HostBinding("@grow") ?
【发布时间】:2020-07-19 16:27:19
【问题描述】:

我有这个指令用于动画组件高度的变化。但自从我们从 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 ERROR TypeError: Cannot read property '11' of null

Safari 想出了这个:

TypeError: null is not an object (evaluating 'componentLView[RENDERER]')

和火狐:

ERROR TypeError: "componentLView is null"

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

【问题讨论】:

    标签: angular angular2-hostbinding


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2010-11-05
      • 2010-12-06
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      相关资源
      最近更新 更多