27
rated 0 times
[
34]
[
7]
/ answers: 1 / hits: 30818
/ 10 Years ago, wed, march 12, 2014, 12:00:00
Is it possible to pass the HTMLElement to a ng-click configured on a controller?
Here's some sample code:
<div ng-controller=Controller>
<ul ng-repeat=item in items>
<li ng-click=handleThisElement($element) id={{item.id}} >{{item.name}}</li>
</ul>
</div>
Controller:
function ($scope) {
$scope.items = [
{name: 'Bilbo', id='Bilbo'},
{name, 'Frodo', id='Frodo'},
{name: 'Pippin', id='Pippin'},
{name: 'Merry', id='Merry'},
{name: 'Sam', id='Sam'}
];
$scope.handleThisElement = function (element) {
alert(element.id); // should alert (Bilbo || Frodo || Pippin || Merry || Sam)
}
UPDATE:
Don´t get confused, I said that I want get the whole element not only the id from the model.
$event.target - don't works in some versions of IE.
More From » angularjs