【发布时间】:2020-12-04 10:31:20
【问题描述】:
我正在使用 angular ionic 3,当我点击某个按钮时,我得到了这个错误,谁能帮我确定这个?
realestateproductdetails.ts
if (localStorage.getItem('agentdetail')) {
this.agentdetail = JSON.parse(localStorage.getItem('agentdetail'));
for (let i = 0; i < this.agentdetail.branchDetails.length; i++) {
this.branchCodeArray[i] = this.agentdetail.branchDetails[i].branchCode
}
从“for”开始的第 3 行是第 66 行
错误
Runtime Error
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at new RealestateproductdetailsPage (realestateproductdetails.ts:66)
at createClass (core.js:12491)
at createDirectiveInstance (core.js:12326)
at createViewNodes (core.js:13784)
at createRootView (core.js:13673)
at callWithDebugContext (core.js:15098)
at Object.debugCreateRootView [as createRootView] (core.js:14381)
at ComponentFactory_.create (core.js:11278)
at ComponentFactoryBoundToModule.create (core.js:4030)
at NavControllerBase._viewInit (nav-controller-base.js:441)
at c (polyfills.js:3)
at Object.reject (polyfills.js:3)
at NavControllerBase._fireError (nav-controller-base.js:223)
at NavControllerBase._failed (nav-controller-base.js:216)
at nav-controller-base.js:263
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.js:4760)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
at polyfills.js:3
【问题讨论】:
-
嘿,在这里附上你的代码。
-
先生是哪一部分?
-
您的错误出现在
realestateproductdetails.ts66行,您尝试从未定义的变量访问属性长度。为了修复它,您需要从该行发布完整代码 -
好的先生发布它
-
请阅读这篇文章。它肯定会帮助你写出一个好问题。 stackoverflow.com/help/how-to-ask