search

Home  >  Q&A  >  body text

angular.js - ng automatically gets focus

Input automatically obtains focus currently using js. How to write it using ng?

PHPzPHPz2832 days ago1102

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-15 17:09:40

    My idea is to write an instruction and then attach the instruction to the input

    var myApp = angular.module('myApp',[]);
        myApp.directive('autoFocus', function(){
              return function(scope, element){
                element[0].focus();
              };
        });

    reply
    0
  • Cancelreply