satya satya - 1 year ago 71
AngularJS Question

Can not order drop down list value alphabetically using angular.js

I have an issue.The drop down list can not ordered alphabetically using angular.js . I am explaining my code below.

<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Business Name :</span>
<select class="form-control" id="restau" ng-model="restaurant" ng-options=" for qua in listOfRestaurant | orderBy:'name' track by qua.value" ng-change="getDayFromSpecial('restau');">

name:'Select Business Name',

headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
var data={'name':obj.rest_name,'value':obj.member_id};
},function errorCallback(response) {

Here my problem is i can order the list but
Select Business Name
is coming in middle in this list which should come only first and selected. Please help me resolve this issue.

Answer Source

you can write like this.

<select name="quarter" ng-model="Quarter" 
        ng-options="obj.value as obj for obj in options | orderBy:'toString()'">
        <option value="" >Select Business Name</option>

don't put your select business name in data list.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download