0

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)

Muhad
  • 283
  • 1
  • 5
  • 14
  • May be it does not work for `option`? – Muhad Sep 26 '15 at 22:18
  • So, the `$scope.selectedYear` have correlated indices with the `$scope.data.dateList.year` array? In other words, is the `$index` that you use correct for the `selectedYear` array? – New Dev Sep 26 '15 at 22:21
  • I just compare two variables `year.id` and value from return of function thats contains type int – Muhad Sep 26 '15 at 22:23
  • The `$scope.selectedYear` is not used in `ng-model` of select list. It is separeted variable – Muhad Sep 26 '15 at 22:24
  • But you are using `$index` of one array (`data.dateList.year`) as the index to access the item of another (`selectedYear`). I'm asking if it was intentional. Are these two arrays aligned? Perhaps, add the sample data of each array – New Dev Sep 26 '15 at 22:25
  • 1
    Please provide demo that includes enough data to replicate this. We have no idea what `selectedYear` contains. Also no need for a function to make the comparison – charlietfl Sep 26 '15 at 22:26
  • `$index` is by `ng-repeat`. Yes, `$scope.selectedYear` contains indexes same as `$scope.data.dateList.year` – Muhad Sep 26 '15 at 22:27
  • I updated question about `selectedYear` – Muhad Sep 26 '15 at 22:27
  • @Muhad does this question relates to http://stackoverflow.com/q/32570809/2435473 which asked for some sort of same question.. – Pankaj Parkar Sep 26 '15 at 22:29
  • I have seen this question and had tried to build own case. I use current code on basement this question. But have problems – Muhad Sep 26 '15 at 22:31
  • @Muhad where's the demo? You are the one asking for help but we have no way to inspect in browser or see the full code – charlietfl Sep 26 '15 at 22:32
  • Here's a demo that shows that it works (with assumptions I make about your data): http://plnkr.co/edit/lUhkDg96gVWEwBCcffcp?p=preview – New Dev Sep 26 '15 at 22:34
  • It should be two relative select lists. You can add another select list with `ng-change="setSelectedYear($index, 2012)"` It will not work – Muhad Sep 26 '15 at 22:40
  • @Muhad why can't you make the modification and fork the demo so we can see your problem live? – charlietfl Sep 26 '15 at 22:44
  • Sure, this is demo: http://plnkr.co/edit/cSN0EnkqHB1Yz4FGzUVz?p=preview – Muhad Sep 27 '15 at 09:07
  • So, clearly, the demo you provided doesn't correspond to the question. `setSelectedYear` doesn't take `index` and `value`, and both use `[0]` as the index. I suggest you edit your question and make sure it is accurate and complete with respect to the demo. – New Dev Sep 27 '15 at 16:38

0 Answers0