Angular Select 模型更新后未更新
Angular Select not updating after model updates
请看下面的 plunkr,当通过 $http 加载数据时,我将其分配给模型,但 select 没有更新为新值。但是当更改 select 时,模型会正确更新。
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"
>
在你的 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"
有效。不需要轨道 by.
更新的 plnkr:https://plnkr.co/edit/sy25TGPt87C2Nj2Qmzbn?p=preview
请看下面的 plunkr,当通过 $http 加载数据时,我将其分配给模型,但 select 没有更新为新值。但是当更改 select 时,模型会正确更新。
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"
>
在你的 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"
有效。不需要轨道 by.
更新的 plnkr:https://plnkr.co/edit/sy25TGPt87C2Nj2Qmzbn?p=preview