如何将AngularJs变量作为jQuery函数中的参数传递?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将AngularJs变量作为jQuery函数中的参数传递?相关的知识,希望对你有一定的参考价值。

我有这个jQuery函数:

   function updateProfile(profile, sessionId){
    alert(profile,sessionId);
}

html中我喜欢这个

<button onclick="updateProfile(profile, {{sessionId}})">Update</button>

它不起作用,因为{{sessionId}}是angularjs变量。

在jquery onclick函数中传递此angularjs变量的正确方法是什么?

谢谢大家参与!

答案

使用ng-click而不是onclick并在您的范围内定义您的功能

//HTML
<button ng-click="updateProfile(profile, {{sessionId}})">Update</button>

//Angular
$scope.updateProfile = function(profile, sessionId){
    alert(profile,sessionId);
}

以上是关于如何将AngularJs变量作为jQuery函数中的参数传递?的主要内容,如果未能解决你的问题,请参考以下文章