c0D3l0g1c
c0D3l0g1c

Reputation: 3164

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'];

Upvotes: 0

Views: 1216

Answers (3)

c0D3l0g1c
c0D3l0g1c

Reputation: 3164

Figured it out. See revised code:

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

Upvotes: 1

Chandermani
Chandermani

Reputation: 42669

This i believe is issue with minification of your code. Either inject the dependencies as described by @jayaram or use the the [] notation for dependencies and using modules. See the section Notes on Minification here

Upvotes: 0

Jayram
Jayram

Reputation: 19588

You need to include $scope explicitly in your controller like this to make it work.

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


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

Upvotes: 1

Related Questions