Created
October 7, 2013 19:00
-
-
Save bbrewer97202/6873114 to your computer and use it in GitHub Desktop.
angularjs select ng-option example with keys and values from object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html ng-app="selectExample"> | |
<head> | |
<title></title> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script> | |
<script src="select.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<div ng-controller="selectController"> | |
<div ng-repeat="item in items"> | |
<label>{{item.name}} is type: <select ng-model="item.type" ng-options="t.id as t.name for t in types"></select></label> | |
({{item.type}}) | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var selectModule = angular.module('selectExample', []); | |
selectModule.controller('selectController', function($scope) { | |
$scope.items = [ | |
{ id: 1, name: "Item #1", type: 111 }, | |
{ id: 2, name: "Item #2", type: 333 }, | |
{ id: 4, name: "Item #3", type: 222 }, | |
]; | |
$scope.types = [ | |
{ id: 111, name: "Type 1" }, | |
{ id: 222, name: "Type 2" }, | |
{ id: 333, name: "Type 3" } | |
]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment