Angular Material: mat-select not selecting default

后端 未结 17 1348
不思量自难忘°
不思量自难忘° 2020-11-28 23:18

I have a mat-select where the options are all objects defined in an array. I am trying to set the value to default to one of the options, however it is being left selected

17条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 00:02

    Try this!

    this.selectedObjectList = [{id:1}, {id:2}, {id:3}]
    this.allObjectList = [{id:1}, {id:2}, {id:3}, {id:4}, {id:5}]
    let newList = this.allObjectList.filter(e => this.selectedObjectList.find(a => e.id == a.id))
    this.selectedObjectList = newList
    

提交回复
热议问题