Last active
September 12, 2017 20:28
-
-
Save gengue/9d5d7394c85a6c5b915c4f249ac2508a to your computer and use it in GitHub Desktop.
Focus directive angularjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app.layouts').directive('focusMe', | |
function($timeout, $parse) { | |
return { | |
link: function(scope, element, attrs) { | |
var model = $parse(attrs.focusMe); | |
scope.$watch(model, function(value) { | |
if(value === true) { | |
$timeout(function() { | |
element[0].focus(); | |
}); | |
} | |
}); | |
element.bind('blur', function() { | |
console.log('blur') | |
scope.$apply(model.assign(scope, false)); | |
}) | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment