So I have a variable number of input fields and after saving them I'd like to return focus to the first of them.
HTML Code:
<td ng-repeat='col in list.cols'>
<input class='colData' type='text' ng-model='newentry[$index]' on-press-enter="addRow(newentry)">
</td>
As you can probably read I call 'addRow()' when pressing enter and then add the values to my data model. This works fine.
Now after adding the data I would like to set the focus to the first of these input fields.
I am trying to resist the urge to fall back on my jQuery knowledge. If i included jQuery I could just do $('input.colData').first().focus();
.
But I'm really trying to learn to do things 'the angular way'.
How would I approach this scenario?
Is there a way maybe to select an input field by the model it contains?
thanks,
J
UPDATE: I don't think this is a duplicate, as in my case I can't add a directive to the input field, as they are created dynamically by angular and only the first one should be focussed. Their number is, as stated above, variable. I fail to see how to identify the first among them aside from the jQuery one-liner.