I have the following AngularJS code:
<option ng-repeat="year in data.dateList.year" value="{{year.id}}" ng-disabled="year.id < 2012" ng-selected="year.id == 0">
{{year.value}}
</option>
The condition year.id < 2012
works for ng-disabled
. When I change this code to:
ng-disabled="year.id < getSelectedYear($index)"
It does not disable options.
The function getSelectedYear
returns a value from first select list:
$scope.getSelectedYear = function (index){
if($scope.selectedYear[index] != undefined){
return $scope.selectedYear[index];
}
}
If do console.log($scope.selectedYear[index])
I get the value 2012
.
Why does the last case not work?
About $scope.selectedYear
:
This variable is set by ng-change="setSelectedYear(index, value)"
:
$scope.setSelectedYear = function (index, value){
$scope.selectedYear[index] = value;
}
Where index
is same that used in setSelectedYear($index)