如何在打字稿中显示对象值
如何以角度显示对象值。在浏览器开发人员工具中,我得到的对象及其值可以很好。但是无法以形式填充值。
在 *.ts文件中,我得到了:
console.log(this.product), // {"productId": "3", "productName": "G500 cpu", "productDescription": "gaming computer", "productCategory": "computers", "units": 5 }
this.updateForm.patchValue({
// productId: '23128', // display 23128
// productName: 'asdas', // display asdas
productId: this.product.productId, // doesnt display anything
productName: this.product.productName // doesnt display anything
// productId: this.product, // display [object Object]
// productName: this.product // display [object Object]
})
在 *.html中,我得到了:
<form [formGroup]="updateForm">
<div class="form-group">
<input
type="text"
class="form-control"
formControlName="productId">
</div>
<div class="form-group">
<input
type="text"
class="form-control"
formControlName="productName"
/>
</div>
How to display object value in forms in angular. In browser developer tools I am getting the object and its values fine. But can't populate the values in the form.
In *.ts file i got:
console.log(this.product), // {"productId": "3", "productName": "G500 cpu", "productDescription": "gaming computer", "productCategory": "computers", "units": 5 }
this.updateForm.patchValue({
// productId: '23128', // display 23128
// productName: 'asdas', // display asdas
productId: this.product.productId, // doesnt display anything
productName: this.product.productName // doesnt display anything
// productId: this.product, // display [object Object]
// productName: this.product // display [object Object]
})
in *.html I got:
<form [formGroup]="updateForm">
<div class="form-group">
<input
type="text"
class="form-control"
formControlName="productId">
</div>
<div class="form-group">
<input
type="text"
class="form-control"
formControlName="productName"
/>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是分配每个控制值补丁程序对象的整体值,而是
只需确保将“控制名称”和“对象变量名称”匹配。
stackblitz示例
Instead of assigning each control value patch whole value of product object,
just make sure form control name and object variable name should be matched.
stackblitz example