I want to create a list of items, which are simple clickable text. Each time you click on an item it tranforms to an input (textbox) and you can edit it. I have done this already. The only thing I am missing is to set the focus on the input element when I click on the item. My HTML code is the following:
<div ng-repeat="item in items">
<span ng-if="!valueIsEditedForItem(item.id)">
<a href="" ng-click="editValueForItem(item.id)">
{{ item.value }}
</a>
</span>
<span ng-if="valueIsEditedForItem(item.id)">
<input ng-model="edited_value"
ng-keyup="onValueInput($event, item.id, edited_value)"/>
</span>
</div>
The <a>
element and the <input>
element are two different elements. So, my idea is to pass the input element somehow to the ng-click="editValueForItem(item.id)
. It should look something like this:
<a href="" ng-click="editValueForItem(item.id, inputElement)">
{{ item.value }}
</a>
Then I would be able to set the focus to the input element by doing this:
inputElement.focus();
I know that the $event
variable holds the element of the event in $event.target
. But my event is on <a>
and not on <input>
. How can I reference the <input>
element into <a>
?