无论我尝试什么,我都会收到未定义的错误。我有值的时候我console.log(this.EmployeeDetails.gallery);
,gallery[i].path
确实有一个值,但我的浏览器控制台保持促使它,我尝试了不同的方法,如先设置为空字符串,另一个函数中移动的循环,并将其设置等待,一切都不起作用。
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.component.ts.EmployeeEditComponent.loadPhotosAndVideos(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) 在 SafeSubscriber.push ../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:134) at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber. js:77) 在 Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) 在 MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/ map.js.MapSubscriber._next (map.js:41) 在 MapSubscriber.push。./node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) at 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)
循环不应该小于或等于长度只是更小,像这样:
for (let i = 0; i < this.EmployeeDetails.gallery.length; i++) {
...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句