使用带有 ng-repeat 的 uib-typeahead 模型不会持续存在 [英] Model does not persist using uib-typeahead with ng-repeat

查看:22
本文介绍了使用带有 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 上复制(基于 ui-bootstrap 的演示).(通过选择一个状态,然后单击选择另一个"来重现错误.之前选择的状态消失了!)

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?

注意:我也在使用自定义 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,但无济于事.

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

感谢帮助!

推荐答案

我已经检查了你的 plunk,然后试图重现它,但无法弄清楚 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天全站免登陆