-1

I'm not able to enable/disable the autocomplete textfield component dynamically or otherwise.

I want the component to be disabled by default. And later on some user activity, like on click of a button this should enable the component.

I tried the following code but didnt work:

export class MyComponent {
  // this DIDN'T WORK
  opts:object={value: "", disabled: true};
  ctrl= new FormControl(this.opts);

  ngDoCheck(){  
    // this DIDN'T WORK
    // this could be ngOnChange, ngOnInit or button click event
    if(this.IsTextBoxEnabled){
      this.ctrl.enable();
    }else{
      this.ctrl.disable();
    }
  }
}

How to do this in Angular Material Autocomplete component?

UPDATE:
Similar issue on SO was also left unanswered. To which I responded with my answer.

Temp O'rary
  • 5,366
  • 13
  • 49
  • 109

1 Answers1

1

I got this working by doing this.

<input [attr.disabled]="IsTextBoxDisabled?'true':null">

Apparently I found this here.

Temp O'rary
  • 5,366
  • 13
  • 49
  • 109