AngularJS Tutorial - Bind select to scope








The following code shows how to Bind select to scope.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
'use strict';<!--from   w  ww  .  j a  v a 2  s . c o  m-->
var app = angular.module('myApp', []);
function FooListCtrl($scope) {
    $scope.foos = {"Bar": [ "foo", "bar"]};
    $scope.selected = [];
}
</script>
</head>
<body>
  <body ng-app="myApp" ng-controller="FooListCtrl">
  <span ng-repeat="foolist in foos">
    <select ng-model="selected" ng-options="foo for foo in foolist" multiple="multiple">
    </select>
      {{selected}}
  </span>
  {{selected}}
</body>
</body>
</html>

The code above is rendered as follows: