htmlangularjshtml-selectng-optionsangularjs-select

My ng-option select bar is showing the last value in the list


Here is my HTML

<select ng-if="list[$index].length>0" data-ng-model="form1value[$index]"
        data-ng-options="label for label in obj.child track by $index">
</select>

I am getting the last value in obj.child as selected by default. I want to write 'select' in the select bar


Solution

  • You can use the following approach (--Select-- will be the default selected option):

    <select ng-if="list[$index].length>0"  data-ng-model="form1value[$index]">
        <option value="">--Select--</option>
        <option ng-repeat="item in obj.child track by $index" value="{{item}}">{{item}}</option>
    </select>