我有以下AngularJS代码:
<option ng-repeat="year in data.dateList.year" value="{{year.id}}" ng-disabled="year.id < 2012" ng-selected="year.id == 0">
{{year.value}}
</option>
条件year.id < 2012
适用于ng-disabled
。当我将此代码更改为:
ng-disabled="year.id < getSelectedYear($index)"
它不会禁用选项。
函数getSelectedYear
返回第一个选择列表中的值:
$scope.getSelectedYear = function (index){
if($scope.selectedYear[index] != undefined){
return $scope.selectedYear[index];
}
}
如果console.log($scope.selectedYear[index])
我得到值2012
。
为什么最后一种情况不起作用?
关于 $scope.selectedYear
:
此变量由ng-change="setSelectedYear(index, value)"
:
$scope.setSelectedYear = function (index, value){
$scope.selectedYear[index] = value;
}
index
与setSelectedYear($index)