[英]How do I get hold of a property of typescript object
I have the following code我有以下代码
submitData() {
var search= new ProductSearch();
search=this.profileForm.value;
console.log(search);
console.log(search.Code);
}
The console.log(search) line produces console.log(search) 行产生
{code: "123456"}
{代码:“123456”}
but the console.log(search.Code) line produces但 console.log(search.Code) 行产生
undefined
不明确的
This is the ProductSearch object这是 ProductSearch 对象
export class ProductSearch {
Code:string;
}
不要使用 var 并使用 let 或 const 除此之外你需要使用简单的 c 而不是 C 的代码console.log(search.code);
Form control name is code, you should change it to Code.Try like this.表单控件名称是代码,您应该将其更改为 Code.Try 像这样。
export interface ProductSearch{
Code:string
}
submitData() {
const search:ProductSearch=this.profileForm.value;
console.log(search);
console.log(search.Code);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.