. :
It will iterate over the element and check if the attribute is focusNowtrue or not. Verify that the error handler code sets the expression to true / false.
.directive('focusNow', function ($timeout) {
return {
link: function (scope, element, attrs) {
scope.$watch(attrs.focusNow, function (value) {
if (value === true) {
for (var i = 0; i < element.length; i++) {
var ele = angular.element(element[i].parentNode);
if (!ele.hasClass('ng-hide')) {
element[i].focus();
}
}
}
});
}
};
});
and in HTML, you will have:
<input type="text" focus-now="expression" />
where expressionwill be a normal expression that will be evaluated as true in case of an error.
source
share