I have an input element being created in an AngularJS directive:
<span ng-repeat="phrasePart in phraseParts">
{{phrasePart}}<input ng-attr-id="{{ 'phrasePart-' + $index }}" ng-if="!$last"/>
</span>
and I want the first input element i.e. (<input id="phrasePart-0" /> to receive focus, so I do this with jQuery:
$(function () {
$("#phrasePart-0").focus();
});
However, this code does set focus in an input element that is directly in the HTML and not rendered by AngularJS.
- How can I get jQuery to wait until the input element "phrasePart-0" is created by AngularJS before setting focus?
- Is there an "AngularJS way" to set focus that would be better?