angularjs设置focus

前端之家收集整理的这篇文章主要介绍了angularjs设置focus前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Usage

<input type="text" focus-on="focusMe"/>
app.controller('MyCtrl',function($scope,focus) {
    focus('focusMe');
});

Source

app.directive('focusOn',function() {
   return function(scope,elem,attr) {
      scope.$on('focusOn',function(e,name) {
        if(name === attr.focusOn) {
          elem[0].focus();
        }
      });
   };
});

app.factory('focus',function ($rootScope,$timeout) {
  return function(name) {
    $timeout(function (){
      $rootScope.$broadcast('focusOn',name);
    });
  }
});
原文链接:https://www.f2er.com/angularjs/148985.html

猜你在找的Angularjs相关文章