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.