РЕШЕНО:
import { Component, ViewChild} from '@angular/core';
import { Keyboard } from 'ionic-native';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
@ViewChild('input') myInput ;
constructor() {}
ionViewDidLoad() {
setTimeout(() => {
Keyboard.show() // for android
this.myInput.setFocus();
},150);
}
}
1) импортировать "ViewChild"
import {Component, ViewChild} from '@angular/core';
2) Создайте ссылку на свой вклад в свой шаблон html:
<ion-input #focusInput></ion-input>
3) Используйте @ViewChild, чтобы получить доступ к компоненту ввода, на который вы только что ссылались ранее.
@ViewChild('focusInput') myInput ;
4) Запуск фокуса
Используйте метод ionViewLoaded(), чтобы запускать его каждый раз при загрузке представления/страницы.
setTimeout не требуется
ionViewLoaded() {
setTimeout(() => {
Keyboard.show() // for android
this.myInput.setFocus();
},150); //a least 150ms.
}
4) Покажите клавиатуру на Android
import { Keyboard } from 'ionic-native';
Вызовите клавиатуру .show(), чтобы вызвать клавиатуру на Android.
5) Показать клавиатуру на iOS
добавьте эту строку в свой файл config.xml, чтобы она работала на iOS:
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
С помощью великой статьи mhartington: http://mhartington.io/post/setting-input-focus/