0

I'm working with Angularjs.

HTML:

<select name="questionId1" ng-model="abCtrl.form.questionSel.q1" ng-options="question.val for question in abCtrl.form.questions track by question.index"></select>

<select name="questionId2" ng-model="abCtrl.form.questionSel.q2" ng-options="question.val for question in abCtrl.form.questions track by question.index"></select>

I'd like the option the user selects will be disabled for the other selection and vice versa

1
  • why are you don't use two different model? Commented Oct 26, 2015 at 12:18

4 Answers 4

2

Replacing ng-options with ng-repeat-ed options can be assimilated to a regression...

You can use ... disable when ... syntax in ng-options:

First ng-options:

...  disable when (question.index === questionSel.q2)  ...

Second ng-options:

...  disable when (question.index === questionSel.q1)  ...

Here is a fiddle

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

Comments

1

Try to use different approach, like this

<select name="questionId1" ng-model="abCtrl.form.questionSel.q1">
<option ng-repeat="question in abCtrl.form.questions" value="{{question.val}}" 
ng-disabled="abCtrl.secondSelectValue == question.val"
ng-selected="abCtrl.firstSelectValue == question.val">{{question.val}}
</option>
</select>

abCtrl.firstSelectValue would be default value of ur select box (otherwise it would have empty selection first time)

3 Comments

and just invert this for second select
do you think it's possible doing that using just <select> tag?
Because in that way the first option is like '<option value="? object:35 ?"></option>'
0

Two ways:

1 Comment

I have two different select with same options value and content, I want to disable in selB what I've selected in selA and vice versa
0

Could you please try on angular ngDisabled there is lot of example's available in net could you please surf it . Also here I am attaching some sample code like

for ngDisabled

<!DOCTYPE html>
<html ng-app="sample">
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<script>
   angular.module('sample',[]).controller('sampleCntrl',function($rootScope){
   $rootScope.disableVal= true;
   });
</script>
<div ng-controller="sampleCntrl">
<p>
<button ng-disabled="disableVal">Click Me!</button>
</p>
<p>
<input type="checkbox" ng-model="mySwitch"/>Button
</p>
<p>
<button ng-disabled="disableVal">Click Me!</button>
</p>
<p>
<input type="checkbox" ng-model="mySwitch"/>Button
</p>
<p>
{{ mySwitch }}
</p>
</div> 
</body>
</html>

2 Comments

I've to disable the option selected in selA into selB... how can ng-disabled help me?
I updated the answer please check and my idea is set the ngDisabled var as $rootScope .Then where ever we click it will automatically update's every where we used also concentrate on ng-model.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.