简体   繁体   English

Angular JS ng-click with arguments

[英]Angular JS ng-click with arguments

Suppose my html looks like 假设我的html看起来像

 <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 问题是在发送该参数时无法调用批准用户,因此如何将其发送到该函数

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 . 双花括号绑定表达式( {{ }} )告诉Angular它应该评估双花括号内的表达式,并将结果插入DOM中代替原始绑定表达式。

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. 您只需访问该对象并使用属性值并将其传递给您的方法即可。

删除括号{{ }}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM