Search code examples
angularjsselectng-options

track by not working on select change value not getting selected


I have written code like below

 <select ng-model="selectedseasId" ng-options="seas.seasInternalId as seas.seasName for seas in seass track by seas.seasInternalId"> </select>

$scope.selectedseasId = 3;

I have data like

var seass = [   {
        "seasInternalId" : 4,
       "seasName": "My Second seas"  
      },
         {
        "seasInternalId" : 3,
       "seasName": "My Second seas"  
      }
      ];

No value is getting selected in select box. Is there anything wrong with my code?


Solution

  • ng-options track by and select as are not compatible. See this link

    Surely you don't need the track by ID as I suppose seasInternalId is unique, so seas.seasInternalId as seas.seasName for seas in seass should suffice and work.