kadoshms / ionic2-autocomplete

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

Suggestions list is not showed up when only first character is entered #151

Open Gehazzz opened 6 years ago

Gehazzz commented 6 years ago

Suggestions list is not showed up when only first character is entered. image List of suggestions is returned properly from getResults method of defined dataProvider, but not displayed. It appears only after click or after the next typed character. image

getResults method:


getResults(keyword: string) {

        let config = {
            types: ['(cities)'],
            input: keyword
        }

        return new Observable(observer => {
            this.autocompleteService.getPlacePredictions(config, (pred, status) => {                

                observer.next(pred);
           });
     });
}

Angular version is 5.2.9. SetFocus doesn't help. Is there any other way to show it up? How this can be fixed? Thank you.

AamirAlam commented 6 years ago

Well this works fine in my case i have make some changes in getResult function. Instead of returning trainList directly first check if the data is fetched or not if not return an empty array instead of returning an undefined object. ` getResults(keyword:string) {

return this.sham(keyword).filter((item) => { return item;

   });  

}

sham(keyword:string){

   this.http.get("assets/data/trainName.json")
   .map(res => res.json()).subscribe(data =>{ 
   // const data = trainAutocomplete;

   var trainArray = [];
     this.delay = 0;
   var i = 0 ;
   var sham = [];
  for (var key in data.trains)
    {
      console.log(key)
      i = i + 1;
      if (i < 4)

    {

   sham[key] =  data.trains[key].name +" "+"("+data.trains[key].number+")";

      }

else{

  break;
}

}

   this.trainArray = sham ;

  });
  if(this.trainArray!=undefined) { 
    return this.trainArray;
  }
  else {
    return this.trainArray = [];
  }

  }

`

oliviercherrier commented 6 years ago

It works also for me. It is probably a problem with the creation of your observable.