Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery Uncaught TypeError: Cannot call method 'anyFunc' of undefined on calling angular function

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 284
    Comment on it

    As per my point of view this error can be because of the following two points:

    1.  If the ID is not provided to the element  correctly.

    2. If the function is called before the DOM is loaded therefore try to write your function call inside the window.onload event.

    Example:

    <body ng-app="app">
        <div id="mainDiv" ng-controller="MyCtrl">
       <input type="button"/ id="temp">
       </div>
    </body>
    
    
    angular.module('app', [])
        .controller('MyCtrl', function ($scope) {
        $scope.anyFunc = function () {
            alert("I am called from jQuery");
           };
    });
    
    
    window.onload = function () {
    
     $("#temp").on("click",function()
         {
           angular.element($("#mainDiv")).scope().anyFunc();
        });
    
    }

     

                                                                                       Hope it helps...!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: