Search code examples
htmlangularjsselectangularjs-ng-optionsng-modal

ng-options with multiple select/Checkbox


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?


Solution

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