javascript - mat-select 下拉补丁值不起作用?
问题描述
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>
组件.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-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 + '';
推荐阅读
- reactjs - 如何使用反应更改组件中传输的值的值?
- python - python selenium 无法找到谷歌地图术语和服务的元素
- macos - 如何使用 windows Visual Studio 发布到 MacOS
- javascript - 当每个步骤可用时,如何进行链式提取并显示结果?
- python - 在python中使用快速排序对链表进行排序
- javascript - 如何更改我的公式语法以使用变量
- c++ - 是否允许在一个翻译单元中使用显式返回类型并在另一个翻译单元中使用推导返回类型?
- python - 在python中查找给定元素右侧的第一个非零元素的索引
- python - 如何从字典中创建一个数据框,使每个条目都是一个列表?
- c# - Entity Framework Core 2.1.14 DB First Missing Foreign Key on a misconfigured data type 的非主候选键