9

I want to know that how can I call a jQuery function in my angular function, like I've a jquery function like:

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.

2

3 Answers 3

11

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

myApp.controller(AppCtrl,['$scope', function($scope) {
    $scope.imagesData = function() {
        testData();//calling jquery function visible in given scop
        jQuery('#id').next();//getting element sibling
    }
}]);
Sign up to request clarification or add additional context in comments.

Comments

2

I tried this.I hope it might help. Js:

function testData(){

  return ("entering");
}

var myapp = angular.module("myapp",[]);
myapp.controller("ctrl",['$scope', function($scope) {

  $scope.imagesData = testData;

   console.log($scope.imagesData());
 }]);

Working Jsbin

Comments

1

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.

2) Give its reference/include it before angularjs in the html

3) You can directly call the function in the controller.

Yet for the purpose of using jquery, you can call any method using Jquery() just add the Jquery package before angularjs.

1 Comment

Hi, Thanks, it gave my solution too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.