Angular 4 select disabled无效
发布时间:2020-12-17 17:29:57 所属栏目:安全 来源:网络整理
导读:我想在Angular 4中禁用select. 我编写了如下代码但未禁用select. 在组件中: import { FormBuilder,Validators,FormGroup } from '@angular/forms'; this.eventForm = this.formBuilder.group({ // ... some codes ... 'state': [true,Validators.required],
我想在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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读