luanshaofeng的程序人生

nodejs mongodb go vi mysql

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);
    });
  }
});
阅读更多
上一篇csv转mongodb
下一篇youcompleteme为nodejs安装tern-completer项目根目录需要.tern-project文件
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭