Set autofocus true in ion-searchbar


#1

How can I set autofocus true in Search Bar by default or On ‘ionViewDidLoad’?

I am doing like below but not working …

@ViewChild('mainSearchbar') searchBar: Searchbar;

ionViewDidLoad(){ 
      this.seachBar.setFocus();
      /// --- Or --- // 
     this.searchBar._searchbarInput.nativeElement.autofocus = true;
}

#2
ionViewDidEnter() {
  setTimeout(()=>{
      this.searchBar.setFocus();
  }, 150);
}

#3

@anatolys, Thanks…it’s working…!! Bravo…!!


#4

I have search bar in modal and when i do it like you say the modal is close any idea???
Thanks


#5