[英]How to get the value and the text in an Angular Material mat-select
[英]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.