0

This code sample displays properly but does not select the correct option:

<select name="number" ng-model="subscribe.number" ng-required="true">
   <option ng-repeat="i in createArrayFromNumber(event.free) track by $index" value="{{ $index + 1 }}">{{ $index + 1 }}</option>
</select>

Here is a JSfiddle to reproduce.

ng-model is supposed to select the correct option or am I supposed to set a selected attribute in the <option> tag?

1 Answer 1

1

You shoud use ng-selected construct.
For example:

<option ng-selected="{{ condition_for_marking_this_item_as_selected }}" ng-repeat=... >
Sign up to request clarification or add additional context in comments.

2 Comments

That's odd. So the ng-model here is only bound one way? (only receiving value from select but not setting it?)
That's true. Angular does not check ng-model value (which could be something else than a literal) to "select" option.

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.