Skip to content

Instantly share code, notes, and snippets.

@superchris
Created May 4, 2015 21:58
Show Gist options
  • Select an option

  • Save superchris/04f824f0fbdf4a42104a to your computer and use it in GitHub Desktop.

Select an option

Save superchris/04f824f0fbdf4a42104a to your computer and use it in GitHub Desktop.
JS Bin Select example // source http://jsbin.com/kaboj
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta name="description" content="Select example" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="SelectCtrl as ctrl">
<select ng-model="ctrl.selectedPerson" ng-options="person.name for person in ctrl.people"></select><br/>
Name is: {{ctrl.selectedPerson.name}}<br/>
<select ng-model="ctrl.selectedId" ng-options="person.id as person.name for person in ctrl.people"></select><br/>
Id is {{ctrl.selectedId}}
<script id="jsbin-javascript">
var app = angular.module("app", []);
app.controller("SelectCtrl", function() {
this.people = [
{ id: 1, name: "Chris", age: 41, title: "Occupant" },
{ id: 2, name: "Jim", age: 30, title: "The Man" },
];
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">var app = angular.module("app", []);
app.controller("SelectCtrl", function() {
this.people = [
{ id: 1, name: "Chris", age: 41, title: "Occupant" },
{ id: 2, name: "Jim", age: 30, title: "The Man" },
];
});</script></body>
</html>
var app = angular.module("app", []);
app.controller("SelectCtrl", function() {
this.people = [
{ id: 1, name: "Chris", age: 41, title: "Occupant" },
{ id: 2, name: "Jim", age: 30, title: "The Man" },
];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment