gst
gst

Reputation: 25

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

Upvotes: 0

Views: 54

Answers (2)

Suvra
Suvra

Reputation: 21

0" data-ng-model="form1value[$index]" ng-options="item.value as item.name in obj.child" class="form-control">

Upvotes: 0

Bill P
Bill P

Reputation: 3618

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>

Upvotes: 1

Related Questions