Angular Material: mat-select not selecting default

后端 未结 17 1393
不思量自难忘°
不思量自难忘° 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-28 23:58

    You can simply implement your own compare function

    [compareWith]="compareItems"

    See as well the docu. So the complete code would look like:

      
    {{ option.name }}

    and in the Typescript file:

      compareItems(i1, i2) {
        return i1 && i2 && i1.id===i2.id;
      }
    

提交回复
热议问题