当前位置: 首页 > 知识库问答 >
问题:

ERROR TypeError:无论我尝试了什么,都无法读取未定义的属性“path”

鲁烨熠
2023-03-14

无论我做了什么,我总是得到未定义的错误。当我console.log(This.EmployeeDetails.Gallery);,Gallery[I].path有值时,我确实有值,但我的浏览器控制台一直在提示它,我尝试了不同的方法,比如先设置一个空字符串,移动另一个函数中的for-loop并将其设置为等待,但一切都不起作用。

await this.employeeService.getEmployeeDetails(this.Employeeuuid).subscribe((res) => {
  this.EmployeeDetails = res as Employee[];
  this.data.serviceprice = this.EmployeeDetails.serviceprice;
  this.setEmployees();
  console.log(this.EmployeeDetails.gallery);

  for (let i = 0; i <= this.EmployeeDetails.gallery.length; i++) {
    this.photossrc = this.EmployeeDetails.gallery[i].path;
    const src = this.photossrc;
    const caption = 'Image ' + i + ' caption here';
    const thumb = this.EmployeeDetails.gallery[i].path;
    const album = {
      src: src,
      caption: caption,
      thumb: thumb
    };
    this.albums.push(album);
  }
});

错误类型错误:无法读取EmployeeEditComponent.Push../src/app/pages/employee/Employee-Edit/Employee-Edit/Employee-Edit.Component.ts.EmployeeEditComponent.LoadPhotosandVideoes(Employee-Edit.Component.ts:201)在SafeSubscriber.Next(Employee-Edit.Component.ts:96)在SafeSubscriber.push../Node_Modules/RxJS/_ESM5/Internal/Subscriber.js.SafeSubscriber.__Tryorunsub(Subscriber.js:196)在ber.next(Subscriber.js:134)位于subscriber.push./node_modules/rxjs/_esm5/internal/subscriber.js:77)位于subscriber.push./node_modules/rxjs/_esm5/internal/subscriber.js.next(Subscriber.js:54)位于mapsubscriber.push./node_modules/rxjs/_esm5/internal/subscriber.js.next(Subscriber.js:54)位于mapsubscriber.push./node_modules/rxjs/_esm5/internal/subscriber.js.next(subscriber.js:54)在filtersubscriber.push../node_modules/rxjs/_esm5/internal/operators/filter.js.filtersubscriber._next(filter.js:38)位于filtersubscriber.push../node_modules/rxjs/_esm5/internal/subscriber.js.subscriber.next(subscriber.js:54)

共有1个答案

郭业
2023-03-14

循环不应小于或等于长度只是更小,如下所示:

 for (let i = 0; i < this.EmployeeDetails.gallery.length; i++) {
     ...
    }
 类似资料:
  • 为什么我得到这个错误不能读取未定义的触摸属性? 为什么它不能读取,但它可以读取 当我们使用

  • 问题内容: 我正在制作非常简单的react应用。但是,当我尝试通过onChange事件调用父(实际上是祖父母)组件的方法时,我一直在获取。 这是触发事件的组件/表单(因此,在绑定的父组件上调用方法…是的,因为我通过道具将其从父组件传递下来,所以在方法上使用了.bound(this)。) 这是我如何通过大多数父(祖父母)组件中的props传递该方法的方法。 这是我作为父项(方法所有者和方法调用程序之

  • 我正在测试发送电子邮件与流星js和nodemailer插件: 流星添加捷运:流星NodeEmailer 当页面加载时,我在导航器的控制台上看到错误:无法读取未定义的属性“创建运输”。 那么问题是什么呢? 代码如下: /////////////////////////////////////////// ///////////////

  • 我知道这方面还有很多类似的问题,但没有一个答案是有效的。在我的例子中,我有下面的代码,我正在尝试按分数降序排列记录数组。 最后一个函数是什么给我的问题.如果用户运行以下: var web=[{url:“www.southanpton.ac.uk”,内容:“南安普敦大学提供学位课程和世界一流的研究测试。”,{url:“www.xyz.ac.uk”,内容:“另一种大学考试”},{url:“www”,内

  • 我一直试图让firebase与react一起工作,但出现了此错误 未经处理的拒绝(TypeError):无法读取未定义的fetch D:/Peti/Programming/node/coursewebpage/src/components/coursePage.js:12 9 | const db=firebase.firestore()10 | const myAuthLevel=(fireba

  • 这是我的猫鼬模式: 这是使用Express的Node.js服务器。它具有路由,如果触发该路由,它将使用请求中传递的信息更新用户的购物车。正文: 我打印到终端userCart,正如您在代码中看到的,它返回给我的是: 当服务器执行时,它返回以下错误: 如果我已经在Mongoose中定义了的结构,为什么不定义它?