Angular Material: mat-select not selecting default

后端 未结 17 1441
不思量自难忘°
不思量自难忘° 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:03

    I did it just like in these examples. Tried to set the value of the mat-select to the value of one of the mat-options. But failed.

    My mistake was to do [(value)]="someNumberVariable" to a numeric type variable while the ones in mat-options were strings. Even if they looked the same in the template it would not select that option.

    Once I parsed the someNumberVariable to a string everything was totally fine.

    So it seems you need to have the mat-select and the mat-option values not only be the same number (if you are presenting numbers) but also let them be of type string.

提交回复
热议问题