【问题标题】:How to resolve undefined Input Angular? [closed]如何解决未定义的输入角度? [关闭]
【发布时间】:2019-12-04 23:09:59
【问题描述】:

组件中有输入数据:

  @Input() pupil: Pupil;

在模板中呈现这些数据之前,我需要对其进行映射:

 ngOnChanges() {
    this.pupil.photo = Helper.getPhoto(this.pupil);
  }

但我在未定义中得到错误原因this.pupil,但在我看到填充对象之后。

如何等待 Input 的结果?

在模板中我有*ngIf="pupil"

【问题讨论】:

  • 能否提供父模板?

标签: angular angular6 angular7 angular8


【解决方案1】:

你有错误是正常的。试试这个:

ngOnChanges() {
if(this.pupil!=null){
    this.pupil.photo = Helper.getPhoto(this.pupil);
}
  }

【讨论】:

  • 但它看起来很糟糕,我可以使用生命圈角度吗?
  • 哎呀!问题是有时会在这些值为 null 时调用 ngonChanges!它工作吗?请给我正确的答案?
猜你喜欢
  • 2023-03-21
  • 1970-01-01
  • 2021-01-29
  • 2018-04-12
  • 2020-10-22
  • 1970-01-01
  • 2019-02-25
  • 1970-01-01
  • 2013-05-25
相关资源
最近更新 更多