0

Assuming I have two flag as follows:

var myApp = angular.module('myApp', []);
myApp.controller('booleanController', function($scope, $interval){
$scope.isDisabled = false;
$interval(function(){
    $scope.isDisabled = !$scope.isDisabled;
  }, 1000)
})

And HTML as:

<div ng-app='myApp'>
<div ng-controller="booleanController">
    Disable Option<input type="checkbox" ng-model="disableIt">
    </br>
    Select Two <input type="checkbox" ng-model="checked">
    </br>
    <select ng-disabled="{{disableIt && isDisabled}}">  <=========
        <option value="1">One</option>
        <option value="2" ng-selected="checked">Two</option>
    </select>
</div>
</div>

How do I evaluate ng-disabled with the two expression disableIt and isDisabled?

1 Answer 1

3

Just remove the interpolation. Do:-

 ng-disabled="disableIt && isDisabled"

ng-disabled is looking for truthy value and when you do ng-disabled="{{disableIt && isDisabled}}" You are setting the string "true" or "false" as a value for ng-disabled which is always truthy.

Plnkr

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the input. But even after removing the interpolation it was not working. Even its not working in the plnkr example you posted. isDisabled is true but still it is enabled!!
No. In my plunker it is working. Which browser you are testing. If you select Disable Option it disables the select.
Oops, My bad. Its working fine. What if I want to enable/disable it at interval of 1 sec. I tried this: $interval(function(){ $scope.isDisabled = !$scope.isDisabled; }, 1000) Am I missing anything here?
It works for me on chrome and firefox. Can you show my your demo where it does not work. ALso remember to clear your browser cache

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.