如何在onclick函数中传递angular js变量作为参数 [英] how to pass angular js variable inside onclick function as parameter

查看:55
本文介绍了如何在onclick函数中传递angular js变量作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将 AngularJS 变量作为参数值传递给 onclick() 以调用 javascript 函数.任何人都可以指导我如何做吗?

我的代码:

 <div onclick="deleteArrival({{filterList.id}})" class="table-icon deleteIcon">{{filterList.id}}</div>

解决方案

你应该使用 ng-click,没有理由使用 onclick,因为 angular 为你提供了这个功能

然后你应该将你的函数移动到你的 AngularJS 控制器中,并将它绑定到作用域

$scope.deleteArrival = function(filterListId) { ... };

如果你绝对需要使用 onclick 来调用外部函数,你可以在你的作用域中将函数更改为类似这样的东西,仍然使用上面的 ng-click 属性:

$scope.deleteArrival = function(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函数中传递angular js变量作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆