Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typeahead): Handling array of objects containing value/label pairs #2335

Closed
marco-gagliardi opened this issue Aug 2, 2017 · 2 comments

Comments

@marco-gagliardi
Copy link

marco-gagliardi commented Aug 2, 2017

With the typeaheadOptionField input it is possibile to pick a specific property to be used when the source is an array of objects. But what if I wanted to show one of the object's property as the input value, but assign another object's property as the model value?

Say the source is something like this:

[
    {id: 1, name: "Alabama"},
    {id: 2, name: "Alaska"},
    {id: 3, name: "Arizona"}
]

It is not possibile to make the user see the name property in the form control, and bind the model to the id property instead. Something like..

<input [(ngModel)]="customSelected"
       [typeahead]="statesComplex"
       typeaheadBindTo="id"
       typeaheadOptionField ="name"
       class="form-control">

.. or even better to the entire object itself (sometimes very useful):

<input [(ngModel)]="customSelected"   state
       [typeahead]="let state of statesComplex"
       typeaheadBindTo="state"
       typeaheadOptionField ="state.name"
       class="form-control">
@YevheniiaMazur YevheniiaMazur changed the title Handling array of objects containing value/label pairs feat(typeahead): Handling array of objects containing value/label pairs Jan 16, 2018
@exhtml
Copy link

exhtml commented Jul 20, 2018

+1

@Domainv
Copy link
Contributor

Domainv commented Aug 30, 2018

Closed as duplicate of #749

@Domainv Domainv closed this as completed Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants