[英]mat-select dropdown patchvalue not working?
HTML:(Here I have dropdown to get selected value. I used value binding to get value.I have tried ngModel also but its not working. What is wrong in my code? can you help me?) HTML :(这里我有下拉列表来获取选定的值。我使用值绑定来获取值。我也尝试过 ngModel 但它不起作用。我的代码有什么问题?你能帮我吗?)
<mat-form-field>
<mat-select placeholder="Team NO" formControlName="team" [(value)]="teamNO" required>
<mat-option *ngFor="let list of teamList" [value]="list" >{{list}}</mat-option>
</mat-select>
</mat-form-field>
component.ts组件.ts
teamList = ['1','2','3','4','5','6','7','8','9','10'];
teamNO : any;
ngOnInit(){
this.operatorService.currentEditSchedule.subscribe((result: any) =>{
if(!!result){
console.log(result)
this.teamNO = result.teamNo
}
})
}
Try to use ngModel instead of value in mat-select:尝试在 mat-select 中使用 ngModel 而不是 value:
<mat-form-field>
<mat-select placeholder="Team NO" formControlName="team" [(ngModel)]="teamNO" required>
<mat-option *ngFor="let list of teamList" [value]="list" >{{list}}</mat-option>
</mat-select>
</mat-form-field>
In case you get a number from your backend, it can help to convert it to a string:如果您从后端获得一个数字,它可以帮助将其转换为字符串:
this.teamNO = result.teamNo + '';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.