Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-options: how to put empty option at the end?

Currently, I've got something like this (simplified):

<select ng-model=model.policyHolder ng-options="person.index as person.name for person in model.insurance.persons">
  <option value>Someone else
</select>

This creates a dropdown with options for person names and an empty one for "someone else" at the top. The question is, how do I get that empty option at the bottom of the dropdown?

I would very much like to keep using ng-options for this, especially since controlling the position of the default option seems like too small a change to justify the slightly more verbose <option ng-repeat> way.

Thanks!

like image 823
Thany Avatar asked Aug 19 '15 15:08

Thany


1 Answers

use option with value=""

Like:

<select ng-model="model.policyHolder" ng-options="person.index as   person.name for person in model.insurance.persons">
  <option value="">Someone else</option>
</select>

If you want to show Someone else at the bottom when click on drop-down list you can use.

<select ng-model="model.policyHolder">
    <option ng-repeat="person in model.insurance.persons" value="{{person.index}}">{{person.name}}</option>
    <option value="">Someone else</option>
</select>
like image 73
Shaishab Roy Avatar answered Oct 23 '22 03:10

Shaishab Roy