如何通过的onclick函数参数的内部角度JS变量 [英] how to pass angular js variable inside onclick function as parameter
问题描述
我曾尝试通过AngularJS变量作为参数值里面的onclick()调用JavaScript函数。任何人都可以指导我该怎么办呢?
我的code:
< DIV的onclick =deleteArrival({{filterList.id}})级=表图标deleteIcon> {{filterList.id}}< / DIV&GT ;
您应该使用NG-点击,没有理由使用的onclick的角度为您提供了这一功能。
< DIV NG点击=deleteArrival(filterList.id)级=表图标deleteIcon> {{filterList.id}}< / DIV>
您应该然后将你的函数到AngularJS控制器,并将其绑定到范围
$ scope.deleteArrival =功能(filterListId){...};
如果您确实需要使用的onclick调用外部功能,您可以将功能改成这样的事情在你的范围内,仍使用上面的NG-点击属性:
$ scope.deleteArrival =功能(filterListId){window.deleteArrival(filterListId); };
不过,我看不出一个理由不将其移动到你的范围
I have tried to pass AngularJS variable as argument value inside onclick() to call javascript function. Can anyone guide me on how to do it?
My code:
<div onclick="deleteArrival({{filterList.id}})" class="table-icon deleteIcon">{{filterList.id}}</div>
You should be using ng-click, there is no reason to use onclick as angular provides you with this functionality
<div ng-click="deleteArrival(filterList.id)" class="table-icon deleteIcon">{{filterList.id}}</div>
You should then move your function into your AngularJS Controller, and bind it to the scope
$scope.deleteArrival = function(filterListId) { ... };
If you ABSOLUTELY need to use onclick to call an external function, you could change the function to something like this in your scope, still using the ng-click attribute above:
$scope.deleteArrival = function(filterListId) { window.deleteArrival(filterListId); };
However I can't see a reason not to move it into your scope
这篇关于如何通过的onclick函数参数的内部角度JS变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!