angular - 在角度 9 中选择下拉更改传递模式
问题描述
所有人都在基于传递值的下拉更改方法中传递值,只有我做了一些验证以启用提交按钮。而且我还需要比较两个下拉值,在这种情况下我不知道如何在角度 9 中处理它。并且传递的值是位置请找到屏幕截图
<label for="aCount" class="required">testcount</label>
<select id="testCounts" class="form-control" formControlName="testcount" #testcount
(change)='ontestCountSelected(testcount.value)'>
<option *ngFor="let count of testcountsVal" [ngValue]="count.count">
{{ count.count }}
</option>
</select>
<div class="text-danger"
*ngIf="submitted && listForm.controls.testcount.hasError('required')">
Select count is required
</div>
</div>
public testcountsVal: any[] = [
{ count: '0' },
{ count: '1' },
{ count: '2' },
{ count: '3' },
{ count: '4' }
];
ontestCountSelected(value: string) {
console.log(value);
}
所以这里有两个问题:1)一个是我们如何在角度 9 中比较两个不同的下拉模型。 2)为什么当我在下拉列表中传递值 onchange 方法时,在控制台中的位置获得值
解决方案
问题是您设置formControlName
与 variable 相同#testcount
。
您需要更改#testcount
为#testcount1
并用作(change)='ontestCountSelected(testcount1.value)'
<label for="aCount" class="required">testcount</label>
<select id="testCounts" class="form-control" formControlName="testcount" #testcount1
(change)='ontestCountSelected(testcount1.value)'>
<option *ngFor="let count of testcountsVal" [ngValue]="count.count">
{{ count.count }}
</option>
</select>
推荐阅读
- excel - 即使参考单元格和表格相同,Vlookup 也会返回 #N/A
- kubernetes - 使用 gcloud 访问 Kubernetes 仪表板
- aggregate-functions - 将两个表中包含的值添加为 Hive 中的映射
- performance - Oracle 子查询分解不适用于函数调用
- c# - 通过.shp文件动态绘制地图
- amazon-web-services - s3fuse 是 AWS EFS 的良好替代品吗
- java - 如何在不使用 CardLayouts 的情况下重新加载面板?
- ios - 如何在集合视图中正确呈现渐变视图?
- php - 将 Wordpress 安装移动到其文件夹后的重定向问题
- php - Laravel Chumper/Zipper 删除文件名