Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 未捕获(承诺中):TypeError:无法读取属性';长度';未定义的_Angular_Ionic3 - Fatal编程技术网

Angular 未捕获(承诺中):TypeError:无法读取属性';长度';未定义的

Angular 未捕获(承诺中):TypeError:无法读取属性';长度';未定义的,angular,ionic3,Angular,Ionic3,我正在处理angular ionic 3,当我点击某个按钮时,我发现了这个错误,有人能帮我确定一下吗 realestateproductdetails.ts if (localStorage.getItem('agentdetail')) { this.agentdetail = JSON.parse(localStorage.getItem('agentdetail')); for (let i = 0; i < this.agentdetail.branchDe

我正在处理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
      }
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
if(localStorage.getItem('agentdetail')){
this.agentdetail=JSON.parse(localStorage.getItem('agentdetail'));
if(this.agentdetail&&this.agentdetail.branchDetails&&this.agentdetail.branchDetails.length>0){
for(设i=0;i

这样使用它会起作用,因为this.agentdetail.branchDetails可能为空问题在这行
中(设i=0;i

执行循环时,变量agentdetail中没有值。很可能在此之前的某些代码未能为该变量分配任何值。请调试代码以解决此问题


或者,您可以使用@sangar lal在其回答中提到的检查。

嘿,请在此附上您的代码。先生,您的错误在
realestateproductdetails.ts
第66行,您尝试从未定义的变量访问属性长度。为了修复它,您需要发布该lin的完整代码eokay先生,请阅读这篇文章。它肯定会帮助你写一个好问题。
if (localStorage.getItem('agentdetail')) {
      this.agentdetail = JSON.parse(localStorage.getItem('agentdetail'));
if (this.agentdetail && this.agentdetail.branchDetails && this.agentdetail.branchDetails.length > 0){
      for (let i = 0; i < this.agentdetail.branchDetails.length; i++) {
        this.branchCodeArray[i] = this.agentdetail.branchDetails[i].branchCode
      }
}