javascript 如何在angularjs函数中调用jQuery函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32643963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call jQuery function in angularjs function
提问by Dhana
I want to know that how can I call a jQuery function in my angular function, like I've a jquery function like:
我想知道如何在我的 angular 函数中调用 jQuery 函数,就像我有一个 jquery 函数一样:
function testData(){
// code
}
and I've a angular function like:
我有一个角函数,如:
myApp.controller(AppCtrl,['$scope', function($scope) {
$scope.imagesData = function(){
//here I need to call the function: testData()
}
}]);
so, Please let me know that how can I call my testData() inside the angularjs function($scope.imagesData()). Thanks in advance.
所以,请让我知道如何在 angularjs 函数($scope.imagesData())中调用我的 testData()。提前致谢。
回答by Muhammad Nasir
User defined function are not depended to jQuery. How ever if you want to call jQuery
builtin function you should include jQuery
before angularjs
. Here you should you use jQuery
prefix to avoid conflict with angularjs
function
用户定义的函数不依赖于 jQuery。如果你想调用jQuery
内置函数,你应该jQuery
在angularjs
. 在这里你应该使用jQuery
前缀以避免与angularjs
功能冲突
myApp.controller(AppCtrl,['$scope', function($scope) {
$scope.imagesData = function() {
testData();//calling jquery function visible in given scop
jQuery('#id').next();//getting element sibling
}
}]);
回答by Praveen Raj
回答by VizardCrawler
You can do the Following things:
您可以执行以下操作:
1) Make a js file put that function in the js file ,eg: myFunction.js , include the method test data.
1)制作一个js文件,将该函数放入js文件中,例如:myFunction.js,包括方法测试数据。
2) Give its reference/include it before angularjs in the html
2)在html中的angularjs之前给出它的参考/包含它
3) You can directly call the function in the controller.
3)可以直接调用控制器中的函数。
Yet for the purpose of using jquery, you can call any method using Jquery() just add the Jquery package before angularjs.
然而,为了使用 jquery,你可以使用 Jquery() 调用任何方法,只需在 angularjs 之前添加 Jquery 包。