传递多个参数NG-click方法 [英] Passing multiple argument to ng-click method
问题描述
在我的code我喜欢传递给参数的NG-点击属性中指定的函数。
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>
和在控制器
function deleteUser(index, userId){...}
参数索引去除$ scope.user和user._id用户从MongoDB中取出。我是一个newbee到角JS。
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.
当我试图像这样deleteUser是没有得到调用。如果我通过单个参数它就像魅力,但是当我通过超过其不工作
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
推荐答案
您不需要 {{}}
同时指定参数的事件处理程序( NG-点击
)。正确的语法是 NG-点击=deleteUser($指数,user._id)
:
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>
下面是基于$ C $工作plunker c您所提供(检查控制台看到单击处理程序工作正常):<一href=\"http://plnkr.co/edit/26A4Rj0FScPXYU7z92E6?p=$p$pview\">http://plnkr.co/edit/26A4Rj0FScPXYU7z92E6?p=$p$pview
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
这篇关于传递多个参数NG-click方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!