import { Component, ViewChild} from \'@angular/core\';
import { Keyboard } from \'ionic-native\';
@Component({
templateUrl: \
None of the above was working for me. Here is how I resolved:
import { ElementRef, AfterViewChecked, Directive } from '@angular/core';
import {Keyboard} from 'ionic-native';
@Directive({
selector: '[autofocus]'
})
export class FocusInput implements AfterViewChecked {
private firstTime: boolean = true;
constructor(public elem: ElementRef) {
}
ngAfterViewChecked() {
if (this.firstTime) {
let vm = this;
setTimeout(function(){
vm.elem.nativeElement.firstChild.focus();
vm.firstTime = false;
Keyboard.show();
}, 300)
}
}
}
Then in your ion-input field just add the autofocus attribute:
Tested on Browser and Android not IOS yet but no reason it should not work.