Search code examples
javascriptangularjsng-options

AngularJS: ng-options "non-choice" is not the top


I made my select tag directive of the private use

template html

<div>
  <select ng-model="model" ng-options="item as item[labelName] for item in array">
    <option ng-if="!!hasTop" value="">non choice</option>
  </select>
</div>

"array" is return value of $recource.query

With "non choice" in the top, I want to have. ex

  Select
    +-"non choice"
    +-option a
    +-option b

but, not work

  Select
    +-option a
    +-option b
    +-"non choice"

help me.

Additional requirements

It became the top when I deleted ng-if. but. In this directive, I want to control display of "non choice" with an attribute Is there a good idea?


Solution

  • If I understood it correctly, You need to set an empty options at the top. In that case use like below

    <select ng-model="model" ng-options="item as item[labelName] for item in array">
        <option value="">non choice</option>
      </select>