I have a checkbox and input. What I want to do is to disable the input when the checkbox is checked, and enable the input when the checkbox is unchecked.
This is my form group:
this.workingTime = this.fb.group({
toggle: false, // this is the checkbox
from: [{ value: null, disabled: false }],
to: [{ value: null, disabled: false }]
});
get toggleControl() { return this.workingTime.get('toggle'); }
I was sure this will work:
<input [disabled]="toggleControl.value">
But I'm getting a warning in the console:
It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true when you set up this control in your component class, the disabled attribute will actually be set in the DOM for you. We recommend using this approach to avoid 'changed after checked' errors.
I can't use
from: [{ value: null, disabled: this.toggleControl.value }]
Because toggleControl is not yet accessible.
Any ideas? Thanks
workingTime.values.toggle
. MaybetoggleControl().value
? – Joshua Chan