简体   繁体   中英

How to display mat-select with a default value on load

Here is my markup:

  <mat-form-field class="col-md-3" *ngIf="isShown">
    <mat-select placeholder="Status" formControlName="batchStatus" [value]="selected">
      <mat-option *ngFor="let Status of statusList"[value]="status.referenceDetailCode">
        {{ status.referenceDetailValue }}
      </mat-option>
    </mat-select>
  </mat-form-field>

ts code :

this.isShown = true;
this.selected = res.status;

With the above code, dropdown is not getting selected with the status that I'm setting in my typescript file.

它的工作this.displayForm.controls.status.setValue(this.selected);this.displayForm.controls.status.setValue(this.selected);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM