Model does not persist using uib-typeahead with ng-repeat

余生长醉 提交于 2019-12-11 10:48:15

问题


I am trying to use uib-typeahead to select one or more objects (via an ng-repeat), but facing an issue where the model does not persist when adding another object.

This is reproduced on Plnkr here (based on ui-bootstrap's demo). (Reproduce the error by selecting a state, then clicking "Select another". The previously selected state disappears!)

What is causing the model to not persist? How can this be fixed? Is it an issue with uib-typeahead? Or the ng-repeat scope?

NB: I am also using a custom ngModel formatter, but that doesn't appear to be causing any issue; the issue remains when removing the format-state directive.

I have tried setting ng-model-options, to no avail.

Help appreciated!


回答1:


I've went over your plunk and then tried to reproduce it and couldn't figure out what's the directive's problem with ng-repeat. maybe I'me missing something, maybe it's an issue, you might want to ask this question at their github issue tracker.

But I've found that by binding the model value to a model property rather than a model itself does make everything work fine.

Instead of

ng-model="selected" 

Use this

ng-model="selected.state" 

and it now works.



来源:https://stackoverflow.com/questions/36872456/model-does-not-persist-using-uib-typeahead-with-ng-repeat

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