首页 > 解决方案 > formControlName 显示 [object,object]

问题描述

我的 FormControl 有一个 JSON 对象,我将它绑定到相应的字段并[object,object]在视图中查看结果。

let fSource = {
 name: 'India',
 code: 'IN'
};

this.myForm.get('defaultLocation').setValue(fSource);

但我只需要在输入字段中显示名称(印度)。我该如何绑定它?

标签: angular

解决方案


你的意思是?

 this.myForm.get('defaultLocation').setValue(fSource.name);

推荐阅读