ui-focus.js 504 B

123456789101112131415161718
  1. angular.module('app')
  2. .directive('uiFocus', function($timeout, $parse) {
  3. return {
  4. link: function(scope, element, attr) {
  5. var model = $parse(attr.uiFocus);
  6. scope.$watch(model, function(value) {
  7. if(value === true) {
  8. $timeout(function() {
  9. element[0].focus();
  10. });
  11. }
  12. });
  13. element.bind('blur', function() {
  14. scope.$apply(model.assign(scope, false));
  15. });
  16. }
  17. };
  18. });