Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An angular directive/service for giving focus to elements with a tabIndex
(function() {
var app = angular.module('mcbFocus', [])
.directive('focusOn', function() {
return function(scope, elem, attr) {
if(attr.tabIndex === undefined){
elem.attr('tabindex', -1);
}
scope.$on('focusOn', function(e, name) {
if (name === attr.focusOn) {
elem[0].focus();
}
});
};
})
.factory('focus', function($rootScope, $timeout) {
return function(name) {
$timeout(function() {
$rootScope.$broadcast('focusOn', name);
});
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.