Dynamically enable and disable a angular material input field

Discussão em 'Angular' iniciado por parascus, Dezembro 21, 2024.

  1. parascus

    parascus Guest

    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

    Continue reading...

Compartilhe esta Página