Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选择的被动表单选项是formcontrol中的对象_Javascript_Angular - Fatal编程技术网

Javascript 选择的被动表单选项是formcontrol中的对象

Javascript 选择的被动表单选项是formcontrol中的对象,javascript,angular,Javascript,Angular,在我的组件中,我有以下成员存储: stores : Store[] 存储是以下接口: export interface Store{ store_name: string; owner: string; display_name?: string; } 我的html中有以下内容: <select [formControlName]="stores" > <option value="null" hidden s

在我的组件中,我有以下成员存储:

stores : Store[]
存储是以下接口:

export interface Store{
  store_name: string;
  owner: string;
  display_name?: string;
}
我的html中有以下内容:

  <select [formControlName]="stores" >
    <option value="null" hidden selected>Select</option>
    <ng-container *ngIf="selectedProduct">
        <option *ngFor="let store of stores" [value]="store">
            {{ store.display_name }}
        </option>
      </ng-container>
    </select>
为什么在我的onSubmit方法中,当我尝试访问所选存储的字段时,我会变得未定义

onSubmit(){
    console.log(this.fg.get("stores").value.store_name); // undefined
     .....
}

顺便说一句:使用角度10。

使用
[ngValue]
而不是
[value]
?@JasonWhite它起作用了,你能解释一下原因吗?我通过谷歌搜索了解了区别,tnx:)两者之间的唯一区别是值始终是字符串,在ngValue中可以传递的对象
[value]
始终是字符串,如果要绑定对象,则需要使用
[ngValue]
onSubmit(){
    console.log(this.fg.get("stores").value.store_name); // undefined
     .....
}