Angular 6 Follow up: [attr.disabled] in option value disables all entries

跟風遠走 提交于 2019-12-06 09:52:12

To disable elements just use attribute disabled rather than true or false. To enable it again, you need to remove the disabled attribute. In your code [attr.disabled] is setting the value to true or false, what you need is just use [disabled] instead of [attr.disabled].

  <option>Test FALSE</option>
  <option disabled>Test TRUE</option>

  <option *ngFor="let dropDownTestx of adapters" 
      [ngValue]="dropDownTestx" 
      [disabled]="dropDownTestx === 'vmnic2'">
      {{dropDownTestx}}
  </option>

Updated your stackblitz here.

If your're using Reactive Form, not use (change)="...", subscribe to change. Moreover, in html use myForm.get('myControl').value to refer to the value to a control

<div class="select" formGroupName="uplinksMgmt">
   <select formControlName="uplink2" id="uplink2Id" class="selectBox" 
      <!--remove the (change)
      (change)="changedVal($event.target.value)"
      -->
      >
      <option *ngFor="let uplink2x of nicAdapters" 
           [attr.disabled]="inputForm.get('uplik2').value=== dropdown1Val" 
           [ngValue]="uplink2x">{{uplink2x}}
      </option>
   </select> 
</div>

//in your .ts after create the form
this.inputForm.get('uplink2').valueChanges.subscribe(value=>{
   ..you logic here..
   console.log(value);
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!