Ngx-bootstrap: Typeahead option field method?

Created on 12 Sep 2017  路  4Comments  路  Source: valor-software/ngx-bootstrap

The documentation states that typeaheadOptionField _"Supports nested properties and methods."_
How is a method used?
I tried this:
(typeaheadOptionField)="mapTypeaheadField($event)"
and this:
typeaheadOptionField="mapTypeaheadField($event)"

having this:

mapTypeaheadField(event){
   console.log('ev', event);
   return 'name';
}

and my method is never called.

How can I have a method that returns the correct option field? I see the existing tickets that fixed this but no-one ever mentions how to implement this.

EDIT: Reading #1434 more carefully I believe there's not a real method that can be passed at the option field.

What I try to accomplish is something like that:

typeaheadOptionField="description.find(desc => desc.lang === {{currentLang}}).value"

So every object in my array is of the format:

{
   code: "string",
   description: [
    {lang: string,
     value: string
    }]
}

and I'm searching the value property.

If anyone can help it would be nice.

EDIT 2: I tried to make a pipe for it and realized what I was trying wouldn't work. Turns out I'm making a new list out of all the properties I want to use, but I still would like to know if there is (gonna be) a method implemented for the typeahead option field, or at least a better documentation over the existing cases.

can be closed? comp(typeahead)

Most helpful comment

How would you display it as a pipe transformed string?
{ firstName: 'John', lastName: 'Doe'
So the typeaheadOptionField would read John Doe

All 4 comments

(typeaheadOptionField)="mapTypeaheadField($event)"
and this:
typeaheadOptionField="mapTypeaheadField($event)"

These bindings are incorrect:
(typeaheadOptionField) is binding to an event like (click),
typeaheadOptionField is string setter so you can't pass method as an argument.
Correct form of binding if you're using a method is [typeaheadOptionField]="mapTypeaheadField()"

Closing for no updates.

How would you display it as a pipe transformed string?
{ firstName: 'John', lastName: 'Doe'
So the typeaheadOptionField would read John Doe

You object needs to have a function
{ firstName: 'John', lastName: 'Doe', getName: function() { return this.firstName + ' ' + this.lastName} }

Then you can call the function
typeaheadOptionField="getName()"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RolfVeinoeSorensen picture RolfVeinoeSorensen  路  3Comments

ravirajhalli picture ravirajhalli  路  3Comments

MihaiHoriaPopescu picture MihaiHoriaPopescu  路  3Comments

KimBum picture KimBum  路  3Comments

phmello picture phmello  路  3Comments