Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) {
like image 304
Nate Avatar asked Jun 25 '14 13:06

Nate


People also ask

What is rootScope apply ()?

$scope.$apply() This function is used to execute an expression in Agular. The function expression is optional and you can directly use $apply(). This is used to run watcher for the entire scope. $rootScope.$digest()

What is rootScope in angular?

All applications have a $rootScope which is the scope created on the HTML element that contains the ng-app directive. The rootScope is available in the entire application. If a variable has the same name in both the current scope and in the rootScope, the application uses the one in the current scope.

How many rootScope can Angular JS application have?

An app can have only one $rootScope which will be shared among all the components of an app.

What is the difference between scope and rootScope?

The main difference is the availability of the property assigned with the object. A property assigned with $scope cannot be used outside the controller in which it is defined whereas a property assigned with $rootScope can be used anywhere.


1 Answers

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) {
like image 152
tymeJV Avatar answered Sep 18 '22 13:09

tymeJV