Pregunta

I am trying to make the value attribute equal to the value of what it would look like in the object.

For example:

Object:

$scope.tagSelect = [
        { Name: 'Must have', Value: 1 },
        { Name: 'Must not have', Value: 2 }];

Angular HTML:

<select ng-options="select.Value as select.Name for select in tagSelect" ng-model="tag.MatchLogic"></select>

Output:

  <select ng-options="select.Value as select.Name for select in tagSelect" ng-model="tag.MatchLogic" class="ng-pristine ng-valid">
        <option value="0" selected="selected">Must have</option>
        <option value="1">Must not have</option>
  </select>

That is not exactly what I want. What I want is for the option values to equal what is in my object.

More Like Below:

<option value="1" selected="selected">Must have</option>
<option value="2">Must not have</option>
¿Fue útil?

Solución

I think your way is correct, the model value updates correctly but the HTML value attributes are not the same value. Weird behaviour, but it looks like it's wanted.

ng-options="select.Value as select.Name for select in tagSelect"

http://jsfiddle.net/nicolasmoise/Y8C5A/

Notice how the ng-model is updated with correct value.

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