0

I'm relatively new to AngularJS, so maybe my question is stupid, but I cannot find an answer.

I have prepared example to explain my problem, it can be found here. When controller instantiates it has some values passed from parent scope. In my example:

$scope.modelId = 2;
$scope.sizeA = 2;   // this is initial values 
$scope.sizeB = 180; //   for select elements

Then controller requests from server other values for the lists. It loads:

"sizesA": [1, 2, 6, 9, 10],
"sizesB": [120, 180, 300]

After data is loaded, we can see initialized selects on page:

SizeA: <select ng-model="sizeA" ng-options="s for s in model.sizesA"></select>
SizeB: <select ng-model="sizeB" ng-options="s for s in model.sizesB"></select>

sizeB is initialized to value 180 (as expected), but sizeA is initialized to value 6 (with index 2) instead of value 2.

When I specify $scope.sizeA = 9; in controller (there is no index 9, but there such value) it selects item with value 9.

So the question: how can I tell angular to use value

2

1 Answer 1

1

Add track by:

<select ng-model="sizeA" 
        ng-options="size for size in model.sizesA track by size"></select>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.