简体   繁体   中英

How to add checkbox to each drop down value for Select Control

I am using Angular JS 1 ,

I am displaying values dynamically into select control .

This is my code

<div ng-app="myApp" ng-controller="myCtrl">
<select ng-model="selectedName" ng-options="x for x in names">
</select>
</div>

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.names = ["Emil", "Tobias", "Linus"];
});

http://jsfiddle.net/9fR23/454/

You are not looking for a <select> , just use a ng-repeat to display your checkboxes:

 var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.names = ["Emil", "Tobias", "Linus"]; $scope.selectedNames = []; $scope.select = function(name) { var index = $scope.selectedNames.indexOf(name); if(index < 0) $scope.selectedNames.push(name); else $scope.selectedNames.splice(index, 1); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myApp" ng-controller="myCtrl"> <div ng-repeat="n in names"> <input type="checkbox" ng-click="select(n)"/>{{n}} </div> selected: {{selectedNames}} </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM