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>
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
Ahmed
  • 255
  • 1
  • 6
  • 18
  • You should probably put the `disable` clause in your `ng-repeat` like [the example at the bottom of the docs](https://docs.angularjs.org/api/ng/directive/ngOptions). – Tony Sep 14 '15 at 17:53
  • apply filter and don't show the options only – Pranay Dutta Sep 14 '15 at 17:54

3 Answers3

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

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
1

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

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

Angular Docs

Dalorzo
  • 19,834
  • 7
  • 55
  • 102
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

Sandeep
  • 1,461
  • 13
  • 26