How to add replacement text to the drop-down list

I am new to angularjs. I want to add a placeholder to my dropdown menu. I do not hard code my outliers, it comes from some where. Can you tell me where I was wrong.

<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>

Everything works here. But the placeholder is not in the dropdown menu

+4
source share
5 answers
<option value="" disabled selected>Please Select</option>
+13
source

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>
+4
source

placeholder. SO .

+1

:

<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>

​​ .

 $scope.myModel = "";
+1

I am using Angular v1.6.6. So, check the compatibility of the older version. I believe that the code below should work v1.5 onwards.

$scope.ordertypeList = ordertypeListFromApiCall; // Get the collection from API
$scope.ordertypeList.splice(0,0, {'id' : '', 'name' : 'Select Order Type...' } );                 
$scope.wlOrdActType = $scope.ordertypeList[0];

And in HTML,

<select class="form-control" ng-model="wlOrdActType" required ng-options="ordertype.name disable when ordertype.id == '' for ordertype in ordertypeList track by ordertype.id">
</select>

In the itemSelected function, verify that the object identifier $ scope.wlOrdActType is not empty.

0
source

All Articles