1

Hi I am new to angular js. I want to know how to disable drop down when checkbox is unchecked in angular js.this is the code i have been trying...

Click me:

<input type="checkbox" ng-model="checked"><br/>
<div>
<div class="check-element animate-hide" ng-show="checked">

 <select ng-model="myDropDown">
      <option value="one">One</option>
      <option value="two">Two</option>
      <option value="three">Three</option>
</select>    

3 Answers 3

3

By having checked defined as your checkbox's model you can just that to control whether the select (drop down) is disabled using that variable on your controller's scope.

<select ng-model="myDropDown" ng-disabled="!checked">

make sure you use the negation of checked since you want it to be disabled when the checkbox is not checked.

PLNKR example

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

Comments

1

You can do:

<select ng-model="myDropDown" ng-disabled="!checked">

Use ng-disabled conditionally on if the ng-model for your checkbox is true or false

Comments

0

So, this is a real quick example. Below I have a select box. You can use ng-disabled="EXPRESSION" to dynamically disable stuff.

  <select ng-model="dropdown" ng-options="item.name for item in dropdown" ng-disabled="!checked">
  <input type="checkbox" ng-model="checked">

Just set the expression to check the variable that is true/false on your checkbox. When it is false (unchecked) your dropdown will be disabled

Comments

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.