本文介绍了角度 $rootScope.$on 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在控制器中有以下内容.
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 返回未定义.有人知道这是什么原因吗?
$on is returned undefined. Anyone knows the cause of this?
我的控制器是:
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.$on 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!