在我的应用程序中,我有这样的代码:
"docDecesPere": $scope.orphanFatherDocumentUpload == null ?
(
res.candidatureSituationSociale != "undefined" ?
res.candidatureSituationSociale.docDecesPere :
null
) :
$scope.orphanFatherDocumentUpload.name
在某些情况下,res.candidatureSituationSociale
我是未定义的,所以你可以看到我已经测试过它,所以如果它不是未定义的,我会影响res.candidatureSituationSociale.docDecesPere
“docDecesPere”
,但我总是收到此错误:
Cannot read property 'docDecesPere' of null
那么,尽管我已经对其进行了测试,但为什么我还是会遇到这个问题?我该如何解决它?
最佳答案
您将它们括在 "
中,因此您需要使用 typeof
:
typeof res.candidatureSituationSociale != "undefined"
为了安全起见,还请添加null
。
typeof res.candidatureSituationSociale != "undefined" &&
res.candidatureSituationSociale != null
关于javascript - Catch 无法读取 null 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37023861/