Is it possible to select multiple options from ng-options or have ng-options values as check boxes? If possible can someone give me an example please?
Asked
Active
Viewed 2,553 times
-1
-
1If you want examples, see the documentation for ng-options here. https://docs.angularjs.org/api/ng/directive/ngOptions – nageeb Feb 26 '18 at 18:42
-
@nageeb I think you didn't understand my question. I have a select bar with 5 options, right now I can select a single value from that dropdown, I want to select multiple values as a checkbox. – Amit Tanwar Feb 26 '18 at 19:02
-
I understand your question. However if you don't understand the multiple attribute, which is actually a property of the HTML Select tag, here's documentation on that as well. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select – nageeb Feb 26 '18 at 19:09
1 Answers
0
To create a multiple select just add multiple to your select tag
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script type="text/javascript">
var app=angular.module("myApp", []);
app.controller(
"myCtrl",
function($scope){
$scope.values=[
{value:"0", text:"zero"},
{value:"1", text:"one"},
{value:"2", text:"two"}
];
}
);
</script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<div>Choose:</div>
<select name="choose" ng-model="choose" multiple>
<option ng-repeat="x in values" value="{{x.value}}">{{x.text}}</option>
</select>
</div>
</body>
</html>

John Kane
- 4,383
- 1
- 24
- 42
-
Thanks, @John Kane I just figured it out with your help. I can also use ng-dropdown-multiselect. – Amit Tanwar Feb 26 '18 at 19:23