How to disable option in Angular JS?

前端 未结 3 1947
栀梦
栀梦 2021-01-07 07:04

I have ng-repeat option:

相关标签:
3条回答
  • 2021-01-07 07:34

    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

    0 讨论(0)
  • 2021-01-07 07:43

    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

    0 讨论(0)
  • 2021-01-07 07:43

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

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

    Angular Docs

    0 讨论(0)
提交回复
热议问题