Nate
Nate

Reputation: 2084

Angular $rootScope.$on Undefined

I have the following in a controller.

$rootScope.$on('progressbarEvent', function (event, data) {
    $rootScope.progresscurrent = data.currentprogress;
    console.log('Event listening: ' + $rootScope.progresscurrent);
});

I have this in a factory service.
   $rootScope.$emit('progressbarEvent', dataFactory.currentprogress);

$on is returned undefined. Anyone knows the cause of this?

My controller is:

app.controller('indexcontroller', ['$rootScope','$scope', '$http', 'dataFactory',
       function ($scope,$http,$rootScope, dataFactory) {

Upvotes: 7

Views: 8210

Answers (1)

tymeJV
tymeJV

Reputation: 104775

The order of dependencies has to be consistent with the array it was declared in:

app.controller('indexcontroller', ['$rootScope','$scope', '$http', 'dataFactory',
   function ($rootScope, $scope, $http, dataFactory) {

Upvotes: 25

Related Questions