【发布时间】:2016-04-20 16:18:24
【问题描述】:
我在服务中有这些变量:
months: [
{ label: 'January', value: 1, disabled: true },
{ label: 'February', value: 2, disabled: true },
{ label: 'March', value: 3, disabled: true },
{ label: 'April', value: 4, disabled: false },
{ label: 'May', value: 5, disabled: false },
{ label: 'June', value: 6, disabled: false },
{ label: 'July', value: 7, disabled: false },
{ label: 'August', value: 8, disabled: false },
{ label: 'September', value: 9, disabled: false },
{ label: 'October', value: 10, disabled: false },
{ label: 'November', value: 11, disabled: false },
{ label: 'December', value: 12, disabled: false }
],
currentMonth: 4
我的选择如下所示:
<select name="goalStartMonth" id="goalStartMonth" class="form-control gb-select" ng-model="startMonth" ng-change="frequencyUpdated()" ng-options="month.value as month.label for month in months"></select>
构建<select> 效果很好,但我想禁用当前月份之前的月份(不能选择过去的月份)
ng-options 的 Angular 文档显示:
"数组中的值禁用时标签禁用"
所以我试过了:
<select name="goalStartMonth" id="goalStartMonth" class="form-control gb-select" ng-model="startMonth" ng-change="frequencyUpdated()" ng-options="month.value as month.label disable when month.value < currentMonth for month in months"></select>
这打破了<select> - 不呈现任何选项。
我也试过了:
<select name="goalStartMonth" id="goalStartMonth" class="form-control gb-select" ng-model="startMonth" ng-change="frequencyUpdated()" ng-options="month.label disable when month.value < currentMonth for month in months"></select>
同样的结果。
我在这里错过了什么?
【问题讨论】:
-
你用的是什么版本?
-
似乎在那个版本中不可用。在 1.4.0 中,您的代码有效
-
好吧,当我将 angular api 文档切换到 1.3.11(显然默认为最新版本)时,这很尴尬,“禁用时”从文档中神奇地消失了 - 你是对的先生!。
标签: javascript angularjs angularjs-directive ng-options