ionic2-autocomplete icon indicating copy to clipboard operation
ionic2-autocomplete copied to clipboard

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

Open Gehazzz opened this issue 6 years ago • 2 comments

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.

Gehazzz avatar Mar 20 '18 19:03 Gehazzz

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 = [];
  }
  
  }

`

AamirAlam avatar May 31 '18 18:05 AamirAlam

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

oliviercherrier avatar Jun 02 '18 07:06 oliviercherrier