0

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>
2
  • That's actually necessary? Because you know, your model does have the right Value. Commented Apr 17, 2014 at 18:32
  • 1
    See stackoverflow.com/questions/13692921/… Commented Apr 17, 2014 at 18:33

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

3 Comments

My tag.MatchLogic is set from the db in some instances. I is just stored as an id value example 1 or 2. When I bring it in it doesn't automatically select the corrent id. Instead it is blank in the select box.
So something like this jsfiddle.net/nicolasmoise/Y8C5A/1? Works fine for me
Hmm I found it is deefiniety making the html option selected but just not selecting it. must be a style issue? will work on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.