使用ng-repeat的uib-typeahead不能持久化模型 [英] Model does not persist using uib-typeahead with ng-repeat

查看:96
本文介绍了使用ng-repeat的uib-typeahead不能持久化模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用uib-typeahead(通过ng-repeat)选择一个或多个对象,但是面临一个问题,即添加另一个对象时模型无法持久保存.

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.

此内容在此处的Plnkr上 复制(基于

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!)

是什么导致模型无法持久?如何解决? uib-typeahead是否有问题?还是ng-repeat范围?

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:我还使用了自定义的ngModel格式化程序,但这似乎没有引起任何问题.删除format-state指令时,问题仍然存在.

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.

我尝试将ng-model-options设置为无效.

帮助表示赞赏!

推荐答案

我检查了一下您的塞子,然后尝试重现它,但无法弄清ng-repeat指令存在什么问题.也许我丢失了一些东西,也许是一个问题,您可能想在他们的github问题跟踪器中问这个问题.

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.

代替

ng-model="selected" 

使用此

ng-model="selected.state" 

它现在有效.

这篇关于使用ng-repeat的uib-typeahead不能持久化模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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