In
the post ng-bind directive we saw
on how to bind values to simple textbox elements, in this example we shall see
on how to bind a list of values to a drop down control.
<html ng-app="bindApp">
<head>
<meta charset="utf-8">
<title>AngularJS - Basic</title>
<script src="angular.min.js"></script>
<script>
var app = angular.module('bindApp', []);
function bindController($scope) {
$scope.myLanguages = [
{
"code": "en",
"name": "English"
},
{
"code": "de",
"name": "German"
}];
};
</script>
</head>
<body>
<div ng-controller="bindController">
<select
ng-model="myLanguage"
ng-options="value.code as value.name for value in myLanguages">
<option>--</option>
</select>
<div>
Selected Language: {{myLanguage}}
</div>
</div>
</body>
</html>
Output
<html ng-app="bindApp">
<head>
<meta charset="utf-8">
<title>AngularJS - Basic</title>
<script src="angular.min.js"></script>
<script>
var app = angular.module('bindApp', []);
function bindController($scope) {
$scope.myLanguages = [
{
"code": "en",
"name": "English"
},
{
"code": "de",
"name": "German"
}];
};
</script>
</head>
<body>
<div ng-controller="bindController">
<select
ng-model="myLanguage"
ng-options="value.code as value.name for value in myLanguages">
<option>--</option>
</select>
<div>
Selected Language: {{myLanguage}}
</div>
</div>
</body>
</html>
Output
No comments:
Post a Comment