我想在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>
当我在
option
标签中添加[disabled]="true"
时,该选项标签会被禁用,但我想禁用select
标签本身。我尝试过以下方法 -<select formControlName="stepStrengh" disabled="{{state ? '': 'disabled'}}">
但是这个也不起作用,当我将状态变量从 true->false
或者 false->true
改变时。
formControlName="stepStrengh"
后,所有的工作都像你所期望的那样正常运行。 - Kraken