如何禁用 Angular JS 中的选项? [英] How to disable option in Angular JS?
问题描述
我有 ng-repeat
选项:
<option ng-repeat="year in data.dateList.year" value="{{year.id}}" ng-disabled="(year.id < 2015) ? true : false>
你可以看到 ng-disabled="(year.id < 2015) ? true : false"
如果 year.id
小于 2015,为什么我的选项没有被禁用?
这是我的新代码:
<option ng-repeat="year in data.dateList.year" ng-disabled="(year.id) < formData.beginYear[$index]">{{年.值}}</选项>
这里需要使用 ng-options 来禁用选项
更新
对于两个输入字段相互依赖,你可以像下面那样做.主要问题是当您进行比较时,它是字符串,因为 value
属性将值转换为 string
格式.您可以使用 ng-options
来保留值 & 的 dataType
进行比较时会更容易.
标记
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>
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>
这篇关于如何禁用 Angular JS 中的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!