Angular 角度材质md select在预填充时不显示值

Angular 角度材质md select在预填充时不显示值,angular,angular-material2,angular4-forms,Angular,Angular Material2,Angular4 Forms,我有一个嵌套表单,一个组中的一个组: this.formBuilder.group({ ... placeFirst: this.formBuilder.group({valy: ['', Validators.required]}), ... }) 当我想用预填充的数据更新表单时: this.listingForm.get'placeFirst.valy'.setValuelisting.placeFirst 表单是预填充的,因为我可以

我有一个嵌套表单,一个组中的一个组:

this.formBuilder.group({
        ...
        placeFirst: this.formBuilder.group({valy: ['', Validators.required]}),
        ...
    })
当我想用预填充的数据更新表单时:

this.listingForm.get'placeFirst.valy'.setValuelisting.placeFirst

表单是预填充的,因为我可以看到用json管道填充的字段,但是md select没有显示标题。HTML是:

<div formGroupName="placeFirst">
  <md-select placeholder="Place" formControlName="valy" (change)="creator.placeFirstSelected($event.value)">
    <md-option *ngFor="let placeFirst of creator.placesFirst" [value]="placeFirst">
      {{placeFirst.title}}
    </md-option>
  </md-select>
</div>

如果我使用“选择”和“选项”而不是“md-select”和“md-option”,我可以看到当前所选选项的标题。

正如@developer033在评论中所说,问题是标记为选中的对象与列表中的对象不相等。由于问题仍然存在,我目前的解决方法只是用键过滤列表:

    const placeFirst = this.placesFirst.filter(el => el.key === placeFirstKey)[0];
    this.listingForm.get('placeFirst.valy').setValue(placeFirst);

请确保检查creator.placesFirst中的选项是否真的等于listing.placeFirst。谢谢,但是listing.placeFirst是我要设置的值,creator.placesFirst是要选择多个值的列表。select表单的实际[value]已经设置好了,正如我在使用{{{listingForm.value | json}时看到的那样,但是md select不会将选项标题更新为表单中已经设置的名称。如果我不使用这种材料,它很好用。。我想你不明白我的意思。。。简而言之,要在md select中绑定正确的值,必须设置精确的对象。。这就是为什么您应该检查listing.placeFirst是否真的等于creator.placesFirst.Ops中的任何选项。不,我根据我从Firebase获得的数据设置了值,所以它是相同的值,但它不来自相同的列表。因此,我必须迭代列表并选择值?可能是的,直到关闭才有打开的PR。