gpt4 book ai didi

javascript - 类型错误 : Cannot read property 'form' of null angular

转载 作者:行者123 更新时间:2023-12-02 23:53:19 24 4
gpt4 key购买 nike

我在我的应用程序中实现嵌套路由,所以我在嵌套组件内创建了嵌套路由模块,然后导入模块并声明组件

但是出现错误:无法读取 null 的属性“form”...我也导入了表单模块。

然后我检查 PendingChangesGuard.canDeactivate (can-deactivate.guard.ts:17)

But getting error: Cannot read property 'form' of null.... I imported form module also.

Then I check PendingChangesGuard.canDeactivate (can-deactivate.guard.ts:17)

最佳答案

防御性编程,在使用变量之前应该检查变量是否为空或未定义。

import { isNullOrUndefined } from 'util';

if(!isNullOrUndefined(component) && component.form.dirty){
// your code
}

关于javascript - 类型错误 : Cannot read property 'form' of null angular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55546107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com