Angular 4 select disabled无效

前端之家收集整理的这篇文章主要介绍了Angular 4 select disabled无效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在Angular 4中禁用select.
我编写了如下代码但未禁用select.

在组件中:

import { FormBuilder,Validators,FormGroup } from '@angular/forms';    

this.eventForm = this.formBuilder.group({
    // ... some codes ...
    'state': [true,Validators.required],'stepStrengh': [10,Validators.nullValidator]
});

在HTML中:

<input type="radio" formControlName="state" [value]="true"/> Enable Step
<input type="radio" formControlName="state" [value]="false"/> Disable Step

<select formControlName="stepStrengh" [disabled]="!eventForm.get('timeslots').value">
  <option [ngValue]="10">10 steps</option>
  <option [ngValue]="15">15 steps</option>
</select>

当我将[disabled] =“true”添加到选项标签中时,该选项标签被禁用,但我想禁用选择标签本身.

我试过这样的 –

<select formControlName="stepStrengh" disabled="{{state ? '': 'disabled'}}">

但是当我将状态变量从true-> false或false-> true更改时,这也无效

解决方法

在阅读了一些文档和其他内容后,我发现这个approcah正在为我工​​作

<select [attr.disabled]="state ? '' : null" formControlName="stepStrengh" >

希望能帮助到你.

Here is a link to stackblitz

猜你在找的Angularjs相关文章