Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ng-select disabled using Reactive forms?

How can I make ng-select disabled? I tried [disabled] property, but it does not work here. Also tried to make it disabled using form control, but nothing works.

Stackblitz example

like image 810
Konstantin Kim Avatar asked Aug 31 '25 03:08

Konstantin Kim


2 Answers

You can disable/enable a form control when you initialize it by setting disabled to true

creds.push(this.fb.group({
  fruitType: this.fb.control({value: 'Apple', disabled: true})
}));

To disable/enable the control later dynamically in your component. You can do so by calling the disable/enable methods for that particular form control.

// To enable form control
fruitType.enable();

// To disable form control
fruitType.disable();
like image 70
nash11 Avatar answered Sep 02 '25 18:09

nash11


If you are looking to disable ng-select in html using any dynamic condition then you can use [readonly] property.

<ng-select 
formControlName="myControl"
[readonly]="condition_resolving_to_true_or_false" 
</ng-select>
like image 23
d1fficult Avatar answered Sep 02 '25 19:09

d1fficult