I have a form (using Angular Material), and I want to disable some of the input fields based on selection values. My code looks as below:
HTML
<mat-form-field class="someclass">
<mat-select placeholder="Select payment method" formControlName="paymentMethod">
<mat-option *ngFor="let payment of paymentMethodOptions" [value]="payment.value">
{{payment.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="someclass">
<input matInput placeholder="Some input" formControlName="testInput">
</mat-form-field>
TS
paymentMethodOptions: payment[] = [
{ value: "opt-1", viewValue: "somevalue" },
{ value: "opt-2", viewValue: "anothervalue" }
];
paymentForm = new FormGroup({
paymentMethod: new FormControl("", Validators.required),
testInput: new FormControl({ value: "", disabled: true }, [
Validators.required
])
});
I want to disable testInput
if the value of the selection is equal to "opt-1"
. I've tried several options, but got different errors and couldn't solve it. Is there any working solution to this? Thanks in advance!