を見つけたのでメモ。
Javascript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
angular.module('app').directive('ngFocus', function($timeout) { return { link: function(scope, element, attrs) { scope.$watch(attrs.ngFocus, function(val) { if (angular.isDefined(val) && val) { $timeout(function() { element[0].focus(); }); } }, true); element.bind('blur', function() { if (angular.isDefined(attrs.ngFocusLost)) { scope.$apply(attrs.ngFocusLost); } }); } }; }); |
HTML
1 |
<input type="text" ng-focus="expression" ng-focus-lost="expression"> |
うん。便利。