[英]ERROR: 'Unhandled Promise rejection: TypeError: Cannot read properties of undefined
Getting this error when run ng test.运行 ng test 时出现此错误。
TypeError: Cannot read properties of undefined (reading 'id') TypeError:无法读取未定义的属性(读取“id”)
this.slotSvc.getFiscalWeek(startDate, 1)
.then(function (data) {
const inductionYear = (data[0].id).split('-')[1];
const shopId = slot.shop.id;
const ohLines = [];
this.slotSvc.getOlLinesForShop(shopId, inductionYear)
.subscribe(function (d) {
_.each(d, function (dataOL) {
let slotLineType;
if (slot.linetype) {
slotLineType = slot.linetype;
} else {
slotLineType = slot.assignedAssetInfo.lineTypes[0];
}
if (dataOL.lineTypes[0] === slotLineType && dataOL.name.includes(slot.assetType)) {
const olJson = { 'id': dataOL.id, 'displayName': dataOL.displayName };
ohLines.push(olJson);
}
}.bind(this));
Seems like you are accessing id props from data that does not exists.好像您正在从不存在的数据中访问 id 道具。 Try to monitor data params and log data if it contains id prop or not.尝试监控数据参数并记录数据是否包含 id prop。
you can do like this const inductionYear = (data[0]?.id).split('-')[1];你可以这样做 constductionYear = (data[0]?.id).split('-')[1];
after putting question mark it will not give any undefined error.加上问号后,它不会给出任何未定义的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.