首页 > 解决方案 > 角常春藤,模板局部变量错误:对象可能为“空”

问题描述

我收到消息错误:“对象可能为‘空’”。在行中modal.customWidth.extra_large

我的代码是:

<app-modal
      #modal
      [active]="hasCurrentProduct$ | async"
      [modalWidth]="modal.customWidth.extra_large">

标签: angular

解决方案


在访问它们的属性之前,您需要检查它modal并且customWidth不为空。

更改modal.customWidth.extra_largemodal?.customWidth?.extra_large


推荐阅读