I have a input box based on the below:
If a change a radio I see that the value changes to true for false:
<pre> {{model_parameters_general.estimationmethod=='ew'}} </pre>
So wow why will the input box be disabled based on true for false?
<input [disabled]="model_parameters_general.estimationmethod=='ew'" [(ngModel)]="model_parameters_general.lambda"
formControlName="lambda" type="text" class="form-control">
EDIT:
In the logs I get this:
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.
Example:
form = new FormGroup({
first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
last: new FormControl('Drew', Validators.required)
});
So I am using a reactive from in rc6.
I set the initial disable to the below:
this.myForm = fb.group({
lambda: new FormControl({value: .99, disabled: true}, Validators.required),
})
So do I enable based on a toggle of a radio input?
For boolean properties you need to set them to null
to get them removed
<input [disabled]="model_parameters_general.estimationmethod=='ew' ? true : null" [(ngModel)]="model_parameters_general.lambda"
formControlName="lambda" type="text" class="form-control">
Try using attr.disabled, instead of disabled
<input [attr.disabled]="disabled?'':null"/>
StackOverflow Answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With