7

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) {
Nate
  • 2,044
  • 4
  • 23
  • 47

1 Answers1

25

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) {
tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • Can you clarify? My function is passing in the same order as the injector. – Nate Jun 25 '14 at 13:36
  • 3
    @Nate -- No it's not...You have $rootScope before $scope in the array, and $scope before $rootScope in the function – tymeJV Jun 25 '14 at 13:40
  • Sorry I was looking at the one you posted which was the fix. That fixed it! – Nate Jun 25 '14 at 14:05