Ionic / How to select several options from the select control (Maximum selection will be only 3 options)?

I am currently using version Ionic 1.3.16. Here I need to select several options in a select control.

Here is 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> 
+6
source share
3 answers

There is no value attribute in select , because when you select an option, it will be displayed in ng-model . In addition, to select multiple, you need to add the multiple attribute to your selection.

Markup

 <select ng-model="selectedValues" multiple> <option ng-repeat="option in options" value="{{option.value}}">{{option.name}}</option> </select> {{selectedValues}} 
+6
source

Just add the multiple attribute to the selection box.

 <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> 

+2
source

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 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 --> 
+1
source

Source: https://habr.com/ru/post/988293/


All Articles