When i'm running an application on Desktop or Android device, input focus is working fine. But it's not working in ios 10 Safari. I am using angularjs.
$timeout(function () {
var input = $element.find('.my-input-box')[0];
input.focus();
}, 500);
When i'm running an application on Desktop or Android device, input focus is working fine. But it's not working in ios 10 Safari. I am using angularjs.
$timeout(function () {
var input = $element.find('.my-input-box')[0];
input.focus();
}, 500);
Share
Improve this question
asked Feb 24, 2017 at 6:53
RohitRohit
3,0574 gold badges27 silver badges51 bronze badges
8
- $timeout(function () { $('#someID').focus(); }, 500); try this – Sanjay B Commented Feb 24, 2017 at 6:59
- check that your input element is in DOM or NOT ? – Akshay Tilekar Commented Feb 24, 2017 at 7:01
- It's in DOM that's why working on Desktop and Android – Rohit Commented Feb 24, 2017 at 7:05
- it might be in DOM in less than 500ms on Desktop and Android, but not on iOS... – n00dl3 Commented Mar 15, 2017 at 8:34
- It also don't work when time out is 2000 – Rohit Commented Mar 15, 2017 at 8:35
3 Answers
Reset to default 3 +25Since you are using angularjs, you should definitely try finding your solution in angular.
Did you try using ngFocus.
I guess it would probably look like this:
html:
<input ng-focus="YourVariable">
And set YourVariable to True.
I found this https://github./angular/material/issues/10080
may be this is helpful to you.
This link said may be it is event/gestured problem.
No need to find the element.You can add a directive instead.
yourApp.directive('autofocus', ['$timeout', function($timeout) {
return {
restrict: 'A',
link : function($scope, $element) {
$timeout(function() {
$element[0].focus();
});
}
}
}]);
and use like :-
<input autofocus type="text"/>
Here is working example