首页 > 解决方案 > 单击角度中的禁用选项时弹出通知

问题描述

(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

我做错了什么?

标签: javascriptangularformgroups

解决方案


垫选择项目禁用无法点击...

material.angular.io/components/select/overview

尝试添加自定义 CSS,您可以使用 [class.nameyourclass]="vehicle.id ==8" 更改 [disabled] 尝试添加仅用于测试的背景红色。


推荐阅读