javascript - How can I put multiple values for ng-disabled in angular js? -


how can put multiple values ng-disabled in angular js?

my problem explained following js fiddle: http://jsfiddle.net/fjf4v/10/

    <div ng-app> <div ng-controller="mycnt">      <h3>a ->> <input type="checkbox" ng-model="check"> </input></h3>     <h3>b ->> <input type="checkbox" ng-model="check"> </input></h3>        <br/>     <input type="checkbox" ng-disabled="check">chkbox1 disabled</input>     <input type="checkbox" ng-disabled="check">chkbox2 disabled</input>     <hr/> </div> </div>  javascript: function mycnt($scope) { // } 

in fiddle, there total 4 check boxes labeled a, b, chkbox1 , chkbox2. looking disable both chkbox1 , chkbox2 after checking 1 of , b checkboxes. however, done halfway. if click on either or b, both these buttons getting checked , below chkboxes getting disabled. but, dont want checked both , b checkboxes if click on 1 of them.

i hope, question.

thank !!

so, said in comments, if want achieve long list of checkboxes, can try way : (yeah example "very long" means 10)

the models
can use simple object contain values of checkboxes, did using ng-repeat, anything, use same iterable object :

<input type="checkbox" ng-repeat="nb in [1,2,3,4,5,6,7,8,9,10]" ng-model="checkmodels[nb]" /></h3> 

this object initialized in controller, didn't specify value, example set checkboxes here :

$scope.checkmodels={}; 

the disabling function
nothing difficult here, instead of long list of || values, iterate through models , return true find checked box :

    $scope.isthisdisabled=function(){      for(var in $scope.checkmodels)      {          if($scope.checkmodels[i])              return true                   }     return false; } 

then, can use function in html :

<input type="checkbox" ng-disabled="isthisdisabled()">chkbox1 disabled</input> 

the modified fiddle test : http://jsfiddle.net/dotdotdot/fjf4v/12/

have fun


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -