模型更新后角选择不更新 [英] Angular Select not updating after model updates

查看:150
本文介绍了模型更新后角选择不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看看下面的plunkr,当数据通过的$ HTTP我把它分配给了模型,但选择不更新为新值加载。但改变选择当模型正确更新。

https://plnkr.co/edit/UJMeR0gregFaavhT5wxs?p=$p$ PVIEW

 <选择ID =proptype_id级=表格控
    NG-模式=proptype_id
    NG-选项=ptypes.id作为ptypes.Description在proptypes ptypes跟踪由ptypes.id
    >


解决方案

在您plunkr你NG选项是这样的(不是你有以上):

  NG选项=ptypes.Description在proptypes轨道由ptypes.ID ptypes

如果你把它改成这样:

  NG选项=ptypes.ID作为ptypes.Description在proptypes ptypes

它的工作原理。没有必要由轨道

更新plnkr: https://plnkr.co/edit/sy25TGPt87C2Nj2Qmzbn?p= preVIEW

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"
    >

解决方案

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

这篇关于模型更新后角选择不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆