I've been using the type ahead directive here which has been working great: http://angular-ui.github.io/bootstrap/#/typeahead
我在这里一直在使用typeahead指令,它运行良好:http://angular-ui.github.io/bootstrap/#/typeahead
My issue is, I've gone from a scenario where I'm using the entire object:
我的问题是,我已经从使用整个对象的场景:
<input type="text" ng-model="MyPerson" typeahead="i as i.Name for i in PeopleSearch($viewValue)" />
To a scenario where I only want part of the object:
对于一个场景,我只想要对象的一部分:
<input type="text" ng-model="MyPerson" typeahead="i.Id as i.Name for i in PeopleSearch($viewValue)" />
At this point, both the model and the textbox will contain the same thing, no matter what is entered for the 'as'. Can anyone explain why this is happening? It seems like the logic should mimic the expression for ng-options, but apparently that's not the case.
此时,模型和文本框都将包含相同的内容,无论输入的是什么。有人能解释一下为什么会这样吗?似乎逻辑应该模拟ng-options的表达式,但显然不是这样。
Here's a demo: http://plnkr.co/edit/5oqlldC3PltnrynqhnAU?p=preview
这是一个演示:http://plnkr.co/edit/5oqlldC3PltnrynqhnAU?p=preview
The textbox should contain the person's name after you select the item.
在选择项目后,文本框应该包含人名。
1 个解决方案
#1
3
Here was my resolution in case anyone else runs into this:
以下是我的决心,以防有人遇到这种情况:
<input type="text" ng-model="MySelectedPerson" typeahead="i as i.Name for i in PeopleSearch($viewValue)" typeahead-on-select="MyPerson = MySelectedPerson.Id" />
#1
3
Here was my resolution in case anyone else runs into this:
以下是我的决心,以防有人遇到这种情况:
<input type="text" ng-model="MySelectedPerson" typeahead="i as i.Name for i in PeopleSearch($viewValue)" typeahead-on-select="MyPerson = MySelectedPerson.Id" />