admin管理员组

文章数量:1336094

I have template which starts like :

<li class="list-group-item" ng-repeat="question in question.ChildQuestions" collapse-toggler ng-click="collapseQuestion(this);"> ...

In collapseQuestion i want to pass object that will be reffered to clicked li, but when i send it like collapseQuestion(this); i get some Object but it seems like it isn't li (i can't get any class of that object to check what exactly it is).

So what is correct way to pass object in ng-click ?

I have template which starts like :

<li class="list-group-item" ng-repeat="question in question.ChildQuestions" collapse-toggler ng-click="collapseQuestion(this);"> ...

In collapseQuestion i want to pass object that will be reffered to clicked li, but when i send it like collapseQuestion(this); i get some Object but it seems like it isn't li (i can't get any class of that object to check what exactly it is).

So what is correct way to pass object in ng-click ?

Share Improve this question asked May 25, 2015 at 12:55 demodemo 6,24519 gold badges83 silver badges158 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

You need to parse the event itself.

ng-click="collapseQuestion($event);"

Then in the function use $event.currentTarget

function collapseQuestion($event) {
    $event.currentTarget //do something with currentTarget
}

This post maybe of use: get original element from ng-click

ng-click="collapseQuestion(question)"

see How I pass an object as a parameter in a ng-click within a ng-repeat? AngularJS

本文标签: javascriptPass object in function with ngclickStack Overflow