0

please see the jsfiddle link http://jsfiddle.net/ounsqcmt/55/

i had used autofocus as like this using angularjs

it is working in google but not working in mozilla firefox

The code is as

<div ng-app="App" ng-controller="AppCtrl ">
    <form>

        <input type="text" />
        <input name="theInput" auto-focus />

    </form>


</div>

var app = angular.module("App", []);

app.controller("AppCtrl", function($scope) {

})

app.directive('autoFocus', function($timeout) {
    return {
        restrict: 'AC',
        link: function(_scope, _element) {
            $timeout(function(){
                _element[0].focus();
            }, 0);
        }
    };
});

The above code is working in googlechrome and internet explorer...but not working in mozilla firefox..

please help me..

thanks in advance

chaitanya k
  • 199
  • 1
  • 3
  • 14

1 Answers1

0

var app = angular.module("App", []);

app.controller("AppCtrl", function($scope) {
       
})
app.directive('autoFocus', function($timeout) {
    return {
        restrict: 'AC',
        link: function(_scope, _element) {
            $timeout(function(){
             window.focus()
                _element[0].focus();
            }, 0);
        }
    };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="App" ng-controller="AppCtrl ">
    <form>
        
        <input type="text" />
        <input name="theInput" auto-focus />
        
    </form> 
</div>