exiong
March 7, 2016, 7:38pm
1
I got a modal with just an input textarea. I want to make the keyboard popup automatically with cursor focused on the input as soon as the page launches.
I tried to add autofocus on the html, does not work
Also I tried:
onPageDidEnter(){
this.element.nativeElement.querySelector('textarea').focus();
}
I got weird issue on iphone.
How do I do that?
1 Like
So it’s probably best not to use autofocus.
Autofocus behaves very differently across platforms and can cause a lot of issues, especially on mobile. You might want to avoid it
ramon
May 17, 2016, 11:23am
3
Exactly the same circumstances and the same problem here.
If you finally find a solution, please share it.
2 Likes
rgecy
September 20, 2016, 1:42pm
5
Here is a directive I found that seems to work well on both Android and iOS.
.directive('focusMe', ['$timeout', function ($timeout) {
return {
link: function (scope, element, attrs) {
if (attrs.focusMeDisable === true) {
return;
}
$timeout(function () {
element[0].focus();
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
window.cordova.plugins.Keyboard.show(); //open keyboard manually
}
}, 350);
}
};
}])
html
<input type="text" focus-me focus-me-disable="showInput" ></textarea>
rgecy
September 20, 2016, 1:45pm
6
Also found this one, but havent tried it. https://github.com/ds82/ng-focusme
Just search angular focusme.
Good Luck
Rgecy
Finally found a solution !!
Hi everyone,
I would like to set the focus on an input at the initialization.
I have followed this great article : mhartington.io/post/setting-input-focus/ (which work great), but i want to do something slightly different by focusing at the initialization :
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
@ViewChild('input') myInput: ElementRef
constructor() {}
ngOnInit() {
conso…
Vishin
January 1, 2017, 7:41pm
8
Thanks Dude. Thank you soo much.