角$ rootScope。未定义$ [英] Angular $rootScope.$on Undefined

查看:225
本文介绍了角$ rootScope。未定义$的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器下面。

  $ rootScope。在$('progressbarEvent',函数(事件数据){
    $ rootScope.progresscurrent = data.currentprogress;
    的console.log('事件监听:'+ $ rootScope.progresscurrent);
});我有这样一个工厂服务。
   。$ rootScope $放出('p​​rogressbarEvent',dataFactory.currentprogress);

$上返回undefined。任何人都知道这个原因?

我的控制器是:

  app.controller('索引控制器',['$ rootScope','$范围,$ HTTP','的DataFactory',
       功能($范围,$ HTTP,$ rootScope,的DataFactory){


解决方案

依赖的顺序必须与它在声明数组是一致的:

  app.controller('索引控制器',['$ rootScope','$范围,$ HTTP','的DataFactory',
   功能($ rootScope,$范围,$ HTTP,的DataFactory){

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) {

解决方案

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) {

这篇关于角$ rootScope。未定义$的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆