我想select在Angular 4中select禁用.我编写了如下代码,但未禁用.
在组件中:
import { FormBuilder, Validators, FormGroup } from '@angular/forms';
this.eventForm = this.formBuilder.group({
// ... some codes ...
'state': [true, Validators.required],
'stepStrengh': [10, Validators.nullValidator]
});
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
当我添加[disabled]="true"到option标记中时,该选项标记被禁用,但我想禁用select标记本身.
我试过这样的 -
<select formControlName="stepStrengh" disabled="{{state ? '': 'disabled'}}">
Run Code Online (Sandbox Code Playgroud)
但是,当我从true->false或更改状态变量时,这也无效false->true