0

I've this simple dropdown:

<select ng-model="v" ng-options="valve.Brand + ' ' + valve.Model + ' ' + valve.Notes for valve in valves track by valve.ValveId">
    <option value="">--Valves--</option>
</select>

I'm also using a web service to retrieve data from database. This data contains the ValveId that it's the parameter (value) I would like to use to set as selected an option of my dropdown.

I've tried this way from my controller:

$scope.v = $scope.valves[data.ValveId];

But it is not working.

Any suggestion?

1 Answer 1

1

Replace your ng-options by:

valve.ValveId as valve.Brand + ' ' + valve.Model + ' ' + valve.Notes for valve in valves

Notice the as key at the beginning, it tells which property should be used as the model value.

The model will now have the ID as the value. Therefore, you can now set it directly:

$scope.v = data.ValveId;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.