It is My First AngularJs Application. In this blog you will learn how to bind dropdownlist using AngularJS step by step.
Create a new website.
Create a new website.

After that Add a web page.

Select web form.

Default.aspx shows like.

We add here a angularjs script file like it is downloaded.
- <script src="script/angular.min.js"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
- var app = angular.module('MyFirstApp', [])
- app.controller('FruiteNameBindcontrol', function($scope)
- {
- $scope.Color = [
- {
- id: '1',
- name: 'Apple'
- }, {
- id: '2',
- name: 'Guava'
- }, {
- id: '3',
- name: 'Papaya'
- }, {
- id: '4',
- name: 'Orange'
- }, {
- id: '5',
- name: 'Strawberry'
- }, {
- id: '6',
- name: 'Watermelon'
- }];
- });
Then finally script is generated like:
- <%--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script> --%>
- <script src="script/angular.min.js"></script>
- <script type="text/javascript">
- var app = angular.module('MyFirstApp', [])
- app.controller('FruiteNameBindcontrol', function($scope)
- {
- $scope.Color = [
- {
- id: '1',
- name: 'Apple'
- }, {
- id: '2',
- name: 'Guava'
- }, {
- id: '3',
- name: 'Papaya'
- }, {
- id: '4',
- name: 'Orange'
- }, {
- id: '5',
- name: 'Strawberry'
- }, {
- id: '6',
- name: 'Watermelon'
- }];
- });
- </script>
After that I have declare controller in body tag like:
Method 1:
Now one more point here, I can also define data-ng-app="MyFirstApp" within html tag. After that I have bind color name in dropdownlist like.
Here I have used data-ng-repeat for iterating values for bind in dropdownlist.
- <body data-ng-app="MyFirstApp" data-ng-controller="ColorNamecontrol">
- <option data-ng-repeat="t in Color" value="{{t.id}}">{{t.name}}
All body code is given below.
- <body data-ng-controller="ColorNameBindcontrol">
- <form id="Form">
- Select Color:
- <select>
- <option data-ng-repeat="t in Color" value="{{t.id}}">{{t.name}}</option>
- </select>
- </form>
- </body>

Method 2:
I can also bind same dropdownlist using given below statement.
- <select data-ng-options="s.id as s.name for s in Color" data-ng-model="col">
Output:


Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

nitin gudalePosted Oct 29, 2020, 3:45 AM
How can i get only unique value to dropdown list
Dharmendra Kumar PanditPosted May 11, 2020, 2:00 PM
Thank you. working well......
Tridip BhattacharjeePosted May 14, 2018, 4:07 AM
Nice article but this code is not clear <select data-ng-options="s.id as s.name for s in Color" data-ng-model="col"> how drowdown will understand what to show as value and what to show as text?
Amit KumarPosted Oct 5, 2017, 6:06 AM
For more help go through http://www.c-sharpcorner.com/article/how-to-fetch-data-from-the-database-using-angularjs-in-web-api2/
Amit KumarPosted Oct 5, 2017, 6:05 AM
Hi, Ruhul, you will have to create a service and send the request through it and get data and bind it.
Ruhul AminPosted Sep 28, 2017, 12:14 AM
I need data from oracle server in select dropdown list , but how ?
Amit KumarPosted Apr 12, 2016, 5:25 AM
Thanks
Gowtham RajamanickamPosted Apr 12, 2016, 2:22 AM
great..