Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Gehazzz opened this issue Mar 20, 2018 · 2 comments
Open

Comments

@Gehazzz
Copy link

Gehazzz commented Mar 20, 2018

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants