簡體   English   中英

TypeError:無法讀取null angular的屬性'form'

[英]TypeError: Cannot read property 'form' of null angular

我在我的應用程序中實現了嵌套路由,所以我在嵌套組件中創建了嵌套路由模塊,然后導入模塊並聲明組件

但是得到錯誤:無法讀取null的屬性'形式'....我也導入了表單模塊。

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

但是得到錯誤:無法讀取null的屬性'形式'....我也導入了表單模塊。

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

防御性編程,你應該在使用之前檢查變量是null還是未定義。

import { isNullOrUndefined } from 'util';

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM