Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

AngularJS ng-options Example to Populate (Bind) Select DropDownList with Options

May 5, 2015
Introduction

Here I will explain 
AngularJS ng-options or ng-repeat example to bind dropdownlist value and text using AngularJS or populate or fill dropdowlist with option values using ng-repeat or ng-options in AngularJS. Generally in AngularJS we can fill or bind dropdownlist using ng-repeat or ng-options methods.


To bind dropdownlist value and text using AngularJS we have different type of methods those are

Method1:

By using ng-repeat method we can bind dropdownlist options like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Binding both value and text in select dropdown in Angular.js</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('sampleapp', [])
app.controller('samplecontrol', function ($scope) {
$scope.sample = [{
id: '1',
name: 'Suresh Dasari'
}, {
id: '2',
name: 'Rohini Alavala'
}, {
id: '3',
name: 'Mahendra Dasari'
}, {
id: '4',
name: 'Madhav Sai'
}, {
id: '5',
name: 'Mahesh Dasari'
}, {
id: '6',
name: 'Sateesh Alavala'
}];
});
</script>
</head>
<body data-ng-app="sampleapp" data-ng-controller="samplecontrol">
<form id="form1">
Select Name:
<select>
<option data-ng-repeat="t in sample" value="{{t.id}}">{{t.name}}</option>
</select>
</form>
</body>
</html>

Method 2:

By using ng-options method we can bind dropdownlist like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Binding both value and text in select dropdown in Angular.js</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('sampleapp', [])
app.controller('samplecontrol', function ($scope) {
$scope.sample = [{
id: '1',
name: 'Suresh Dasari'
}, {
id: '2',
name: 'Rohini Alavala'
}, {
id: '3',
name: 'Mahendra Dasari'
}, {
id: '4',
name: 'Madhav Sai'
}, {
id: '5',
name: 'Mahesh Dasari'
}, {
id: '6',
name: 'Sateesh Alavala'
}];
});
</script>
</head>
<body data-ng-app="sampleapp" data-ng-controller="samplecontrol">
<form id="form1">
Select Name: <select ng-options="s.id as s.name for s in sample" ng-model="col">
<option value="">--Select--</option>
</select>
</form>
</body>
</html>

Live Demo

Check below sample dropdownlist for live demo

Select Name:

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.