Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable select in Angular?

On page is located HTML select list:

<select ng-model="names" disabled="{{disabled}}" name="names" class="form-control input-medium">

And in controller:

$scope.disabled = true;

And ng-change:

$scope.changeSpecialization = function (id){
    console.log(id); // Gives value more that 0
    if(id > 0){
      $scope.disabled = false;
    }
}

How you can see in method changeSpecialization I catch id and check it to zero. Console returns me value more that zero. So after is changed $scope.disabled to false. But on page select list is still disabled.

like image 745
Chaps Avatar asked Mar 20 '26 11:03

Chaps


1 Answers

You should use ngDisabled directive.

This directive sets the disabled attribute on the element if the expression inside ngDisabled evaluates to truthy.

Code Example

<select ng-disabled="disabled" ng-model="names" name="names">
</select>
like image 144
Satpal Avatar answered Mar 23 '26 00:03

Satpal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!