user3648646
user3648646

Reputation: 711

How do I bind a checkbox to a select disabled property using angular data binding?

I have a select control with a couple of options and a check box. The check box needs to control if the select is disabled or not. Initially my code gets it correct but when the value changes in the checkbox the select is not affected. I am sure there is a cool angular way of doing this and was hoping someone could point me in the right direction:

 <input type="checkbox" ng-model="IsEnabled">
 <select disabled="{{scope.IsEnabled}}"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select>

myApp.controller('myCtrl', ['$scope', '$http'
scope.IsEnabled= true;]);

Upvotes: 1

Views: 84

Answers (1)

link
link

Reputation: 2510

You do not need to type "scope" when you are in the markup, just type what is attached to the scope. Also you should be using ng-disabled.

So remove the word 'scope' here.

<select ng-disabled="!IsEnabled">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
</select>

See fiidle: http://jsfiddle.net/eZhZL/7/

Hope this helps.

Upvotes: 1

Related Questions