I'm using the Ionic 1.3.16 version currently. Here I need to select multiple options in my select control.
Here my ionic HTML code:
<div class="list">
<label class="item item-input item-select">
<div class="input-label">
Lightsaber
</div>
<select>
<option>Blue</option>
<option selected>Green</option>
<option>Red</option>
</select>
</label>
</div>
Selecting multiple options vary in different operating systems and browsers: For windows: Hold down the control (ctrl) button to select multiple options. For Mac: Hold down the command button to select multiple options.
By adding the multiple attribute to select, users are able to select multiple options.
To select multiple items, the user has to hold down the shift or ctrl key, then select with the mouse. That's not all you can do with the select and <option> tags. You can also make a multi-layer select box with the <optgroup> element inside a <select> tag.
If you deal with default value xor objects, the cleanest way is to provide a compare function to the [compareWith] attribute. This function takes 2 objects in parameters and returns true if they are equals. This way, existing values in model will be selected at start.
You are missing the value
attribute in select
option, because when you select option it will reflect to the ng-model
.Additionally to select multiple you need to add multiple
attribute in your select.
Markup
<select ng-model="selectedValues" multiple>
<option ng-repeat="option in options" value="{{option.value}}">{{option.name}}</option>
</select>
{{selectedValues}}
Just add the multiple
attribute in the select field.
<div class="list">
<label class="item item-input item-select">
<div class="input-label">
Lightsaber
</div>
<select multiple="multiple">
<option>Blue</option>
<option selected>Green</option>
<option>Red</option>
</select>
</label>
use ng-options to bind data, here is how
in the controller
$scope.values= [
{id:1, name:"value1" },
{id:2, name:"value2" },
{id:3, name:"value3" }
];
$scope.selectedValues= []; //initial selections
and in the view
<label class="item item-input item-select">
<select multiple ng-model='selectedValues'
ng-options="a.name for a in values" >
</select>
</label>
{{selectedValues}} <!-- to preview the selection -->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With