how to Set Dropdown to display Text not by value in angularjs ? [Resolved]

Posted by Kasani007 under AngularJS on 1/30/2017 | Points: 10 | Views : 306 | Status : [Member] | Replies : 1
how to Set Dropdown to display Text not by value in angularjs ?




Responses

Posted by: A2H on: 1/30/2017 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
You can use the ng-model option to selected item in dropdownlist instead of using Value
<select ng-model="selected.item" ng-options="c for c in drpitems"></select> 

Complete Code
<!DOCTYPE html>

<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<select ng-model="selected.item" ng-options="c for c in drpitems"></select>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
//items for dropdownlist
$scope.drpitems = ['FirstItem', 'SecondItem', 'ThridItem', 'FourthItem', 'FiveItem'];
//Set the selected item in scope
$scope.selected = { item: $scope.drpitems[2] };

});
</script>

</body>
</html>


Sample Demo


http://jsbin.com/cazixurohi/edit?html,output

Thanks,
A2H
My Blog

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response