contacts/js/components/focus_directive.js

24 lines
564 B
JavaScript
Raw Normal View History

angular.module('contactsApp')
.directive('focusExpression', function ($timeout) {
2016-03-02 09:35:35 +00:00
return {
restrict: 'A',
link: {
post: function postLink(scope, element, attrs) {
2016-03-19 11:26:17 +00:00
scope.$watch(attrs.focusExpression, function () {
2016-03-02 09:35:35 +00:00
if (attrs.focusExpression) {
if (scope.$eval(attrs.focusExpression)) {
$timeout(function () {
2016-03-07 21:50:03 +00:00
if (element.is('input')) {
element.focus();
} else {
element.find('input').focus();
}
2016-03-02 09:35:35 +00:00
}, 100); //need some delay to work with ng-disabled
}
}
});
}
}
};
});