How to focus on ion input on page enter ? Ionic 3


#1

Good morning
i had an ion input inside my page i want to set focus on it when the page enter ( i tried setFocus() on the ionViewDidEnter() but it didn’t work, knowing that it works perfect if i set a button which trigger the function setFocus on click event)


#2

any answer friends ???


#3
// in HTML file
<ion-input #si placeholder="Search Patient" [(ngModel)]="searchPatientString"></ion-input>

// in TS file
import { ViewChild } from '@angular/core'; 
import { Input } from 'ionic-angular';

--variable
@ViewChild('si') searchInput: Input;

-- in constructor
this.searchInput.setFocus();

#4

i can’t put this.searchInput.setFocus(); in the constuctor cuz when the constructor start it didn’t know yet the variable searchInput (i think)


#5

try to put that in ionViewDidLoad();