Vamshi
Vamshi

Reputation: 55

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.

Upvotes: 0

Views: 50

Answers (1)

Vamshi
Vamshi

Reputation: 55

It worked by doing this : this.displayForm.controls.status.setValue(this.selected);

Upvotes: 1

Related Questions