0

I am having this issue and hope someone can help me. Here's the code:

               <div class="country-form">
                <select multiple class="form-control">
                    <option ng-click="countryChanged(country)"
                            ng-model="selectedCountries" ng-repeat="country in options.countries">{{country}}
                    </option>


                </select>
            </div>

I have $scope.selectedCountries = []; in my controller I am not exactly sure how I can preset some countries. Any help will be appreciated.

THank you

cpu2007
  • 905
  • 4
  • 11
  • 24
  • possible duplicate of [Working with select using Angular's ng-options](http://stackoverflow.com/questions/13047923/working-with-select-using-angulars-ng-options) – przno Sep 16 '14 at 12:21

1 Answers1

0

You can use ng-selected in the options to preset some of the countries..

<option ng-selected="(selected.indexOf(country)!=-1)"
    ng-click="countryChanged(country)"
    ng-model="selectedCountries"
    ng-repeat="country in options.countries">{{country}}
</option>

Working demo: http://www.bootply.com/i3xutUdpeP

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
  • Thank you skelly, it works but what I don't understand is why you used $scope.selected as opposed to selectedCountries.Can't the ng-mode be used to preselect so that I can have them removed or added to the array automatically. – cpu2007 Sep 16 '14 at 12:46
  • You can use "selectedCountries" if you want.. it's just a variable name. – Carol Skelly Sep 16 '14 at 12:53