Angular Select not updating after model updates

╄→尐↘猪︶ㄣ 提交于 2020-01-06 14:38:12

问题


Please look at the following plunkr, when the data is loaded via $http I assign it to the model but the select doesn't update to the new value. But when changing the select the model updates correctly.

https://plnkr.co/edit/UJMeR0gregFaavhT5wxs?p=preview

<select id="proptype_id" class="form-control"
    ng-model="proptype_id"
    ng-options="ptypes.id as ptypes.Description for ptypes in proptypes track by ptypes.id"
    >

回答1:


In your plunkr your ng-options is this (not what you have above):

ng-options="ptypes.Description for ptypes in proptypes track by ptypes.ID"

If you change it to this:

ng-options="ptypes.ID as ptypes.Description for ptypes in proptypes"

It works. No need for the track by.

Updated plnkr: https://plnkr.co/edit/sy25TGPt87C2Nj2Qmzbn?p=preview



来源:https://stackoverflow.com/questions/36718995/angular-select-not-updating-after-model-updates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!