【发布时间】:2019-07-15 05:49:59
【问题描述】:
我有一个带有对象数组的 Angular FormControl。 一个对象看起来像:
{id: 'id', title: 'title'}
我在一个带有其他 formControls 的 formGroup 中有一个 formControl。
fc= null;
this.fc= new FormControl(this.array);
this.form = this.formBuilder.group({
fc: this.fc,
...
});
现在在我的 html 中有一个垫子选择:
<mat-select formControlName="fc" placeholder="Test" multiple>
<mat-option *ngFor="let op of test" [value]="op.title">{{ op.title }}</mat-option>
</mat-select>
我怎么说formControl应该使用对象的title属性来显示数组中的初始值?如果我只将数组映射到 title 属性,一切正常。
this.fc= new FormControl(this.array.map(x=>x.title));
但我需要表单中的整个对象。
【问题讨论】:
标签: html angular form-control