0

Trying to get a simple binding going with a html select and a scope variable but the select is not populating with the right value.

<select ng-model="noOfReps" name="reps" id="reps">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
          </select>

This is what I have in my controller

$scope.noOfReps = 2;

But the result is a dropdown which has all the values 1 through 6 but nothing is selected by default.

1 Answer 1

0

model value should be a string in order to match with the option value:

If you are setting the option value with the option's value attribute, or textContent, the value will always be a string which means that the model value must also be a string

https://docs.angularjs.org/api/ng/directive/select

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.