繁体   English   中英

Angular 接口 object 属性未定义

[英]Angular interface object properties are undefined

我有一个 object 的以下接口 -

export interface IProduct {
    vendor?: string;
    price?: number,
    quantity?: number,
    savings?: number,
    productId?: number,
    vendorsPrice?: number[],
    title?: string,
    images?: object[]
    ............
}

在我的组件中,我从 API 获得this.product信息。 我必须将一些 object 属性分配给另一个 object ( storedProductInformation ) -

let currentProduct = this.product;
console.log('this.product', currentProduct);
let storedProductInformation = {
    Title: currentProduct.title,
    Product_id: currentProduct.productId,
    image: currentProduct.images[0].thumbnail,
    Price: currentProduct.vendorPrice,
    vendorsPrice: currentProduct.vendorsPrice,
    savings: currentProduct.savings,
    vendor: currentProduct.vendor
};
console.log('storedProductInformation', storedProductInformation);

我想知道当我使用console.log('this.product', currentProduct)记录数据时获取所有信息,但是当记录console.log('storedProductInformation', storedProductInformation) savings我会得到vendorsPrice和 Savings properties are undefined

我错过了什么吗?

提前致谢!

JavaScript 是区分大小写的语言。 请检查您如何设置“this.product”属性。

 this.product.Vendor
 this.product.vendor

检查供应商是否用大写字母书写。

问候

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM