Angular $ rootScope。$ on Undefined

时间:2014-06-25 13:30:53

标签: angularjs angularjs-scope

我在控制器中有以下内容。

$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返回undefined。谁知道这个的原因?

我的控制器是:

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

1 个答案:

答案 0 :(得分:24)

依赖关系的顺序必须与声明的数组一致:

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