2
votes

I've been using the type ahead directive here which has been working great: 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.

Here's a demo: http://plnkr.co/edit/5oqlldC3PltnrynqhnAU?p=preview

The textbox should contain the person's name after you select the item.

1

1 Answers

3
votes

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" />