Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  143] [ 7]  / answers: 1 / hits: 139375  / 11 Years ago, sat, august 3, 2013, 12:00:00

I have a span tag like below which call a function in the controller when clicked.



HTML



<div class=row ng-repeat=event in events>
<div class=col-lg-1 text-center>
<span class=glyphicon glyphicon-trash data={{event.id}} ng-click=deleteEvent()>
</span>
</div>
</div>


Controller



$scope.deleteEvent=function(){
console.log(this);
}


I need to get the value in data attribute in the controller function. I tried using this keyword and $event; neither one worked.



Please help.


More From » angularjs

 Answers
20

Try passing it directly to the ng-click function:



<div class=col-lg-1 text-center>
<span class=glyphicon glyphicon-trash data={{event.id}}
ng-click=deleteEvent(event.id)></span>
</div>


Then it should be available in your handler:



$scope.deleteEvent=function(idPassedFromNgClick){
console.log(idPassedFromNgClick);
}


Here's an example


[#76550] Friday, August 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;