簡體   English   中英

角度5獲取材料選擇值

[英]Angular 5 get Material Select Value

我想使用表單提交從mat-form-field內的mat-select中獲取mat-option值,如何返回mat-option值?

我的HTML文件:

  <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>

我在打字稿文件中的方法:

updateProfileCompany(e){
    console.log(e);
}

您需要使用[(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>

並在提交時訪問

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM