Search code examples
angularng2-bootstrap

Angular2 Bootstrap Typeahead


In Angular2 I can create a typeahead field looking at a datasource using ng2-bootstrap like this:

<input [typeahead]="dataSource.listOfObjects" ... />

Does anyone know if it's possible to have a conditional value that decides if an item is included in the typeahead?

For instance, it may look like:

<input [typeahead]="dataSource.listOfObjects where include == true" ... />

Solution

  • You can make a pipe (in Angular 1 its called as filter) and process your data along with ng2-bootstrap.

    Another way is the make a function in your component which will return filtered data to use in your typeahead.

    <input [typeahead]="functionInYourComponnet()" ... />
    
    
    export class DataComopnent() {
    
      functionInYourComponnet() {
      ...
      ...
      return filteredData;