2

I have ng-repeat option:

<option ng-repeat="year in data.dateList.year" value="{{year.id}}" ng-disabled="(year.id < 2015) ?  true : false">

You can see ng-disabled="(year.id < 2015) ? true : false"

Why my option is not disabled if year.id less than 2015?

This is my new code:

<div class="itm" ng-repeat="a in range(num) track by $index">
   <option ng-repeat="year in data.dateList.year" ng-disabled="(year.id) < formData.beginYear[$index]">
      {{year.value}}
   </option>
</div>
2
  • You should probably put the disable clause in your ng-repeat like the example at the bottom of the docs. Commented Sep 14, 2015 at 17:53
  • apply filter and don't show the options only Commented Sep 14, 2015 at 17:54

3 Answers 3

4

You need to use ng-options here which has way to disable the options

<select ng-model="year"
  ng-options="year.id disable when (year.id < 2015) for year in data.dateList.year">
</select>

Update

For two input field depends each other, you can do it like below. Main problem was while you were doing comparison it was string, as value attributes convert the value to string format. You could use ng-options that does preserves the dataType of the value & will make more easier while making comparison.

Markup

<select ng-model="yr[$index]" 
   ng-options="year.id as year.id for year in years">
</select>

<select ng-model="year" 
   ng-options="year.id disable when (year.id < yr[$index]) for year in years">
</select>

Demo Plunkr

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

9 Comments

upvoted :) and seems like his attempt is working fine though plnkr.co/edit/iW8l2zV9DrTXAKTYYDo6?p=preview
For me does not work for year in data.dateList.year
For ng-option it is possible?
@Ahmed could you modify this plunkr plnkr.co/edit/iW8l2zV9DrTXAKTYYDo6?p=preview with the data you have..
@Ahmed look at the updated answer..which has plunkr and explaination too..why your code was not working..
|
1

ng-disabled is only meant to be use on input elements:

<INPUT
  ng-disabled="expression">
...
</INPUT>

Angular Docs

Comments

1

Use this Code

<option ng-repeat="year in data.dateList.year track by $index" ng-disabled="(year.id) < 2015">{{year.id}}</option>

see this code

1 Comment

What do you mean by Updated Question?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.