Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  143] [ 3]  / answers: 1 / hits: 53049  / 12 Years ago, wed, january 30, 2013, 12:00:00

In my code i like to pass to arguments to the function specified inside the ng-click attribute.



<div class=shout ng-repeat=user in users>
<p>{{user.name}}</p>
<img src=media/images/delete.png ng-click=deleteUser({{$index}},{{user._id}})/>
</div>


and in the controller



function deleteUser(index, userId){...}


the parameter index is to remove the user from $scope.user and user._id to remove it from the mongodb. i am a newbee to angular js.



when i tried like this the deleteUser is not getting called. if i pass single argument it works like charm but when i pass more than its not working


More From » angularjs

 Answers
31

You don't need {{ }} while specifying arguments to an event handlers (ng-click). The correct syntax would be ng-click=deleteUser($index, user._id):



<div class=shout ng-repeat=user in users>
<p>{{user.name}}</p>
<img src=media/images/delete.png ng-click=deleteUser($index, user._id)/>
</div>


Here is a working plunker based on the code you've provided (check the console to see that click handler is working correctly): http://plnkr.co/edit/26A4Rj0FScPXYU7z92E6?p=preview


[#80525] Tuesday, January 29, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jameson

Total Points: 534
Total Questions: 103
Total Answers: 102

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
jameson questions
;