【问题标题】:Angular Select not updating after model updates模型更新后角度选择不更新
【发布时间】:2026-01-01 01:45:02
【问题描述】:

请查看以下 plunkr,当通过 $http 加载数据时,我将其分配给模型,但选择不会更新为新值。但是当更改选择时,模型会正确更新。

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

【问题讨论】:

  • 能否请您也发布您的控制器?

标签: angularjs html-select


【解决方案1】:

在您的 plunkr 中,您的 ng-options 是这样的(不是您上面的):

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

如果你把它改成这样:

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

它有效。无需跟踪。

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

【讨论】: