Search code examples
javascriptangularjsangularjs-scope

AngularJS TypeError: Cannot call method 'apply' of undefined


I get this error in AngularJS:

TypeError: Cannot call method 'apply' of undefined
    at Object.$get.e.$emit (http://localhost/TestPortal/js/lib/angular.min.js:87:296)
    at j (http://localhost/TestPortal/js/lib/angular.min.js:146:351)
    at http://localhost/TestPortal/js/lib/angular.min.js:88:100
    at Array.forEach (native)
    at m (http://localhost/TestPortal/js/lib/angular.min.js:6:193)
    at Object.$get.e.$broadcast (http://localhost/TestPortal/js/lib/angular.min.js:88:63)
    at http://localhost/TestPortal/js/lib/angular.min.js:80:114
    at k.promise.then.i (http://localhost/TestPortal/js/lib/angular.min.js:76:119)
    at k.promise.then.i (http://localhost/TestPortal/js/lib/angular.min.js:76:119)
    at http://localhost/TestPortal/js/lib/angular.min.js:76:352 

When calling this line of code in my controller:

function ClientController($scope, $routeParams, $location, StaticData, Client, IndustryFactory) {
     $scope.$on('$viewContentLoaded', someMethod);
}

Tried below which also doesn't help, same error:

ClientController.$inject = ['$scope', '$routeParams', '$location', 'StaticData', 'Client', 'IndustryFactory'];

Solution

  • Figured it out. See revised code:

    $scope.$on('$viewContentLoaded', function() { someMethod() });