How to set value to mat-select?

3.2k Views Asked by At

How to set the value to mat-select?

    <mat-select formControlName="project" >
      <mat-option *ngFor="let project of projectList" [value]="project.projectid" 
        (click)="projectSelected(project.projectid)">
        {{project.project_name}}
      </mat-option>
    </mat-select>
  </mat-form-field>

I am trying to do it with this code, but it does not work.

this.form.patchValue({
  'project.projectid': 1
});
1

There are 1 best solutions below

0
On BEST ANSWER

I have created a fork at stackblitz, here is the link: https://stackblitz.com/edit/angular-wiccq5

I think your problem is with the [value] because it seems to expect a string and you are passing a number.