2
votes

I'd like to get mat-option value from mat-select inside mat-form-field using form submit, how to return mat-option value?

My HTML File :

  <form (submit)="updateProfileCompany($event)">
  <mat-form-field>
      <mat-select name="company" placeholder="Select Your Company" #companyValue>
      <mat-option *ngFor="let company of companies" [value]="company.id">
          {{company.perusahaan}}
      </mat-option>
    </mat-select>
  </mat-form-field>
  <div align="right">
      <button mat-raised-button >Add Company</button>
  </div>
  </form>

My method inside typescript file :

updateProfileCompany(e){
    console.log(e);
}
1
use two-way binding in mat-select. I hope it helps,ParthS007

1 Answers

0
votes

You need to use [(ngModel)]

 <mat-select name="company" placeholder="Select Your Company" [(ngModel)]="company" #companyValue>
      <mat-option *ngFor="let company of companies">
          {{company.perusahaan}}
      </mat-option>
</mat-select>

and access it on submit

updateProfileCompany( ){
    console.log(this.company);
}