Is it possible set the focus of an input field via a controller once data has loaded (via $resource in this case)?
The input is hidden via ng-show until the data is
Building on koolunix's answer, if you're only looking to focus input elements it may also be useful to find the first input element that is a child of the element with the focus-on directive.
This is useful in the case of an external library abstracting the input element with directives and templates.
.directive('focusOn', function ($timeout) {
return {
restrict: 'A',
priority: -100,
link: function ($scope, $element, $attr) {
$scope.$watch($attr.focusOn,
function (_focusVal) {
$timeout( function () {
var inputElement = $element.is('input')
? $element
: $element.find('input');
_focusVal ? inputElement.focus()
: inputElement.blur();
});
}
);
}
};
});