0

I was getting an issue regarding auto focus in Ionic 4 and Angular 8 App

While I was opening the search modal in app, I wanted to auto focus on search box

2

1 Answer 1

5

For that I found the solution

I have added reference element on Input field

Ionic Code

<ion-input placeholder="Search for Products" #product_id></ion-input> 

Search Modal Component Code

import { IonInput } from '@ionic/angular';
export class SearchModalComponent implements OnInit {

  @ViewChild('product_id', {static:true}) product_id:IonInput;

  ngAfterViewInit() {
    setTimeout(() => {
      this.product_id.setFocus();
    },500);
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Still works with Ionic 5, thanks !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.