0

If I have this html-code:

<select multiple>
    <option selected>
        one
    </option>
    <option selected>
        two
    </option>
</select>

Then I see that by default both options are selected.

However, if I create the html through angular, then only the last element is selected:

<select
multiple
class="form-control"
ng-model="mymodel">
<option selected="selected" ng-repeat="item in myarr.units" value="  {{item.id}}">{{item.name}}</option>
</select>    

When I look at the generated html I see:

<select class="form-control ng-pristine ng-untouched ng-valid ng-empty"  multiple="" ng-model="mymodel">
<option selected="selected" ng-repeat="item in mymodel" value="2" class="ng- binding ng-scope">One</option>
<option selected="selected" ng-repeat="item in mymodel" value="3" class="ng-binding ng-scope">Two</option>
</select>

So both elements got a "selected" but only the last one is selected in GUI. Am I missing something?

1 Answer 1

1

You should use ng-model to bind your selected value instead of using selected in option select.

Plunkr link

    <select name="multipleSelect" id="multipleSelect" ng-model="data" multiple=""
        ng-options="item.id as item.name for item in myarr.units"></select>

$scope.data = [1, 2]; // selected value
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.