Angular Material: mat-select not selecting default

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

    I followed the above very carefully and still couldn't get the initial value selected.

    The reason was that although my bound value was defined as a string in typescript, my backend API was returning a number.

    Javascript loose typing simply changed the type at runtime (without error), which prevented selection the of the initial value.

    Component

    myBoundValue: string;
    

    Template

    
    

    Solution was to update the API to return a string value.

提交回复
热议问题