contacts/js/components/focus_directive.js

24 lines
564 B
JavaScript

angular.module('contactsApp')
.directive('focusExpression', function ($timeout) {
return {
restrict: 'A',
link: {
post: function postLink(scope, element, attrs) {
scope.$watch(attrs.focusExpression, function () {
if (attrs.focusExpression) {
if (scope.$eval(attrs.focusExpression)) {
$timeout(function () {
if (element.is('input')) {
element.focus();
} else {
element.find('input').focus();
}
}, 100); //need some delay to work with ng-disabled
}
}
});
}
}
};
});