10

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);
Rohit
  • 2,987
  • 3
  • 25
  • 50

3 Answers3

3

Since 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.

mlk
  • 388
  • 2
  • 10
0

I found this https://github.com/angular/material/issues/10080

may be this is helpful to you.

This link said may be it is event/gestured problem.

Mukul Bhardwaj
  • 183
  • 1
  • 2
  • 8
0

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

jitender
  • 10,238
  • 1
  • 18
  • 44