javascript - 单击角度中的禁用选项时弹出通知
问题描述
(alert)
当我单击禁用选项时,我试图弹出一个通知。
首先我有这个component.html:
<div class="col-lg-6 col-md-6">
<div class="from-group">
<label for="vehicle"> Vehicle </label>
<select
type="text"
class="form-control"
formControlName="vehicle_index"
(click)="showAlert()"
>
<option value="">--Select a Vehicle--</option>
<option
*ngFor="let vehicle of vehicles; let i = index"
value="{{ i }}"
[disabled]="vehicle.id == 8"
>
{{vehicle.model}} - {{vehicle.plate_number}}
</option>
</select>
</div>
</div>
正如我们所见,我禁用了选项 when id = 8
。
功能showAlert()
:
showAlert(){
if (this.plannedRouteForm.get("vehicle_index").value.disabled == true) {
alert(" Disabled");
}
}
我在想的是,当我单击选项中的值时,我检查是否已禁用?然后显示警报。
但不幸的是NOT WORK
。
我做错了什么?
解决方案
垫选择项目禁用无法点击...
material.angular.io/components/select/overview
尝试添加自定义 CSS,您可以使用 [class.nameyourclass]="vehicle.id ==8" 更改 [disabled] 尝试添加仅用于测试的背景红色。
推荐阅读
- c - 自己的 Malloc 实现冻结在 brk
- postgresql - 将条目插入到跳过唯一性检查的表中
- angular - Bing Maps Angular MapComponent:TypeError:nativeElement undefined
- base64 - 在 Jupyter 笔记本中保存内联图像(Base64)以进行 Markdown 导出
- java - 以有效的方式从排序的链表中删除重复项
- sql - 在不使用 openquery 的情况下,将数据从链接服务器插入 SQL 中的另一台服务器
- entity-framework - GroupBy + OrderByDescending,返回单独的id
- html - 如何创建具有统一笔触宽度的 SVG 多边形?
- reactjs - React hook - 在另一个文件中调度异步等待操作
- swiper - 使用 rollupjs 的 swiper 要求使用 dom7_modular