0

I try to disable and enable a angular material input field in typescript. I found only solutions where the value is set on creation time or in html like

inputField = new FormControl({ value: '', disabled: this.disabled });

I tried using the disable method like

formControl.disable(true);

but this results in the error "Type 'true' has no properties in common with type '{ onlySelf?: boolean | undefined; emitEvent?: boolean | undefined; }'."

As I understood, the onlySelf information indicates if the form or only the single field should be validated, so I tried to set it as an additional parameter like:

formControl.disable( true, { onlySelf: true });

This also does not succeed. Can somebody help me with the correct syntax for dynamically enabling/disabling an input field in Angular?

Best Regards

Parascus

1 Answer 1

1

A FormControl's disable() function does not expect a boolean as the first argument.

  • To disable the control, call the disable() function
  • To enable the control, call the enable() function

This is not very clear in the Reactive Forms guide, so I can understand in the confusion. The API reference has more detail.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.