I've got an angular directive that includes a form field as part of the template. If the focusOnShow attribute is set to true, the directive will attempt to focus on the field when tha directive is added to the page's DOM.
if (scope.focusOnShow) {
var input = el.find('input')[0];
$timeout(function () {
el.find('input')[0].focus();
}, 500); //well this is crap
}
I'm using this in a modal (angular directives for bootstrap), and the focus() is firing before the field is available because of the modal transition time. If I wait .5 seconds, it works without a problem, but that's lame and unreliable. Is there a way to know that the field is "focusable" before attempting to call focus() on it?