[英]Unable to set checkbox value to false when using disabled state in angular v4 with reactive forms
I will build the form with a form builder and include the following: 我将使用表单构建器构建表单,并包括以下内容:
myCheckbox: [{ value: true, disabled: false }, ''],
Then I will try to patch the value, but this will only work if I am going from false to true, not from true to false: 然后,我将尝试修补该值,但这仅在我从false变为true而不是从true变为false时才有效:
this.myForm.get('selectedItem').patchValue({
selectedItem1: [{ value: false, disabled: false }, '']
});
Am I missing something? 我想念什么吗? Everything worked fine, until I used the recommended way for handling disabled state. 一切正常,直到我使用推荐的方法来处理禁用状态。
The checkbox looks like this in the html: 该复选框在html中如下所示:
<label class="checkbox-inline"><input type="checkbox" name="selectedItem1" formControlName="selectedItem1">Week 1</label>
It should just be: 应该只是:
this.myForm.get('selectedItem').patchValue({
myCheckbox: false
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.