kadoshms / ionic2-autocomplete

Ionic 2 autocomplete component
MIT License
149 stars 108 forks source link

How exactly to pass a function as dataProvider? #130

Closed fortuneNext closed 6 years ago

fortuneNext commented 6 years ago

Hi again,

the documentation says that it is possible to pass a simple function that returns an array as dataProvider but it is not documented how exactly the syntax for that is.

Im getting the error "TypeError: this.dataProvider.getResults is not a function" for the line

<ion-auto-complete [dataProvider]="test"></ion-auto-complete>

and error "_co.test is not a function" for the line

<ion-auto-complete [dataProvider]="test()"></ion-auto-complete>

where test is

test(): Array<string> { return ["1", "2"]; }

Am I using it wrong?

Thanks!

b-d055 commented 6 years ago

I am having this same issue. How did you resolve this? I can't seem to find the documentation for it.

fortuneNext commented 6 years ago

My working code looks like this:

<ion-auto-complete [dataProvider]="aFunc.bind(this)"></ion-auto-complete>

aFunc(filter: string): Array<string> { return ["1","2"]; }

mnibras commented 6 years ago

@fortuneNext it's work for me. Thank you!!!

Gregordy commented 5 years ago

Yes thanks a lot, also working for me!! Saved my day!