1

I have an Angular select dropdown that is populated from a constant. When updating the model the select doesn't update and: I am using track by ID but for some reason when an option is selected the whole object is returned instead of just the ID.

Could someone please have a look at this plunkr and let me know where I went wrong. https://plnkr.co/edit/UJMeR0gregFaavhT5wxs?p=preview

<select id="property_type_id" class="form-control"
    ng-model="proptype_id"
    ng-options="ptypes.Description for ptypes in proptypes track by ptypes.ID"
    >
<option value="">Please select Type</option>
                                                    </select>

1 Answer 1

1

try this.

<select id="property_type_id" class="form-control"  
              ng-model="proptype_id"
              ng-options="ptypes.ID as ptypes.Description for ptypes in proptypes track by ptypes.ID">
     <option value="">Please select Type</option>
</select>
Sign up to request clarification or add additional context in comments.

5 Comments

I want the model = ptypes.ID with your change the model now takes the Description, also assigning the value 2 to the model doesn't change the select drop-down to the correct value
Ok thanks, ptypes.ID as ptypes.Description works, updates the model to the correct value, but why doesn't the $http call update the dropdown to the correct val?
Please help me with the second part of my question, I don't want to open a new one: Why doesn't the drop-down update after the model is updated?
what display in console in http call? this console.log(re.data);
Ok removing the "track by" solved my issue, thanks. According to this question I had to ask: stackoverflow.com/questions/36718995/…

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.