Angular Material: mat-select not selecting default

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

    A very simple way to achieve this is using a formControl with a default value, inside a FormGroup (optional) for example. This is an example using an unit selector to an area input:

    ts

    H_AREA_UNIT = 1;
    M_AREA_UNIT = 2;
    
    exampleForm: FormGroup;
    
    this.exampleForm = this.formBuilder.group({
      areaUnit: [this.H_AREA_UNIT],
    });
    

    html

    Unit h m

提交回复
热议问题