JenuRudan
JenuRudan

Reputation: 545

Angular JS ng-click with arguments

Suppose my html looks like

 <h2>Unapproved Users<span class="badge">12</span></h2>
<ul class="list-group" ng-repeat="user in unApprovedUsers">
    <li class="list-group-item">{{user.Name}} <button class="btn btn-success" ng-click="ApproveUser({{user.ID}})">Approve</button></li>

</ul>

the problem is that approve user cannot be called while sending that argument so how can i send it to the function

Upvotes: 2

Views: 459

Answers (2)

Shyju
Shyju

Reputation: 218882

You do not need the {{ }}. You may directly access the user object and it's properties.

ng-click="ApproveUser(user.ID)"

The double curly braces binding expression({{ }}) tells Angular that it should evaluate the expression inside the double curly braces and insert the result into the DOM in place of the original binding expression .

Since you want to access the user object and pass the property value to your function, you do not need {{ }}. You can simply access the object and use the property value and pass it to your method.

Upvotes: 4

Oleksandr T.
Oleksandr T.

Reputation: 77512

Remove brackets {{ }},

ng-click="ApproveUser(user.ID)"

Upvotes: 4

Related Questions