Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS - How to add placeholder text to dropdown

Tags:

angularjs

I am new to angularjs. I want to add a placeholder to my dropdown. I am not hard coding my dropdown values, it's coming from some where. Can you tell me where i did mistake.

<div class="row form-group">
    <label class="col-md-3">Action<span style="color: #b94a48">*</span></b></label>
    <div class="col-lg-3 col-md-7" style="padding: 0px;">
        <div class="dropdown select" style="width: 100%;">
            <select name="wlOrdActType" class="dropdown multiple" placeholder="-- Please Select --" 
                ng-model="wlOrdActType" 
                ng-options="obj.name as obj.name for obj in ordertypeList"
                style="width: 100%;">
                    <option></option>
            </select>
        </div>
    </div>
</div>

Here every thing is working. But placeholder is not place on the dropdown

like image 507
swetha m Avatar asked Dec 04 '14 08:12

swetha m


3 Answers

<option value="" disabled selected>Please Select</option>
like image 136
binary1101 Avatar answered Oct 19 '22 06:10

binary1101


You can do something like this:

<select ng-model="wlOrdActType" ng-options="obj.name as obj.name for obj in ordertypeList">
  <option value="" selected="selected">Choose one</option>
</select>
like image 25
MatayoshiMariano Avatar answered Oct 19 '22 06:10

MatayoshiMariano


Could also try this:

<select required class="form-control" ng-model="myModel" 
ng-options="item as item.title for item in list">
    <option value="" label="-- Select option --" disabled selected="selected">      
    </option>
</select>

While having the model set to an empty string in the controller.

 $scope.myModel = "";
like image 42
Peter Buju Avatar answered Oct 19 '22 07:10

Peter Buju