Pregunta

I'm struggling to understand to documentation for ngOptions

I have a simple array : ['code1' , 'code2'] and I just want to iterate over and construct option value and label as follow :

What I expect :

<select>
    <option value="" class="">All</option>
    <option value="code1">code1.label</option>
    <option value="code2">code2.label</option>
</select>

What I've tried :

<select ng-model="select" ng-options="option  + '.label' for option in ['code1', 'code2']">
    <option value="">All</option>
</select>

What I get :

<select>
    <option value="" class="">All</option>
    <option value="0">code1.label</option>
    <option value="1">code2.label</option>
</select>

See that values aren't what I want .. I tested almost all possible syntax of the documentation without success.

ps: I've simplified the code, but I use angular-translate to translate the received code and put that translation in the option label.

JsFiddle : http://jsfiddle.net/3ekAj/

¿Fue útil?

Solución

I'm guessing what you want is:

<select ng-model="select" ng-options="option  + '.label' for option in ['code1', 'code2'] track by option">
        <option value="">All</option>
</select>

Fiddle: jsfiddle

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top