Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the clicked ElementId in angularjs?

Tags:

I have the following line:

<a href="#" id="12345" data-ng-click="ShowId()"> 

and in my controller I have:

$scope.ShowId = function(){      alert('clicked element id in here: 12345'); }; 

How can I access in my controller ShowId function the id of the clicked element, in my case 12345?

Notice the bind is not within the ng-repeat so I can access the item id or something like that.

like image 471
user2818430 Avatar asked Aug 12 '15 04:08

user2818430


1 Answers

I solved this:

<a href="#" id="12345" data-ng-click="ShowId($event)">     $scope.ShowId = function(event) {    alert(event.target.id); }; 
like image 167
user2818430 Avatar answered Oct 25 '22 14:10

user2818430