AngularJs Multi Select Dropdown Options
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.selected = [ {id:1, name:"Item 1"} ]; $scope.selectedItems = []; $scope.$watch('selected', function(nowSelected){ $scope.selectedItems = []; if( ! nowSelected ){ // if not selected then return return; } angular.forEach(nowSelected, function(val){ $scope.selectedItems.push( val.id.toString() ); }); }); }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <label>Select Items:</label><br> <select multiple ng-model="selectedItems"> <option value="1">Item 1</option> <option value="2">Item 2</option> <option value="3">Item 3</option> <option value="4">Item 4</option> </select> <p> <tt> selectedItems = {{selectedItems}}</tt> </p> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.selected = [ {id:1, name:"Item 1"} ]; $scope.selectedItems = []; $scope.$watch('selected', function(nowSelected){ $scope.selectedItems = []; if( ! nowSelected ){ // if not selected then return return; } angular.forEach(nowSelected, function(val){ $scope.selectedItems.push( val.id.toString() ); }); }); }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <label>Select Items:</label><br> <select multiple ng-model="selectedItems"> <option value="1">Item 1</option> <option value="2">Item 2</option> <option value="3">Item 3</option> <option value="4">Item 4</option> </select> <p> <tt> selectedItems = {{selectedItems}}</tt> </p> </div> </div> </body> </html>
Copyrights@tutorialsplane.com