AngularJS: Uncaught ReferenceError: $rootScope is not defined in run

5.3k Views Asked by At

I am trying to route all unauthorized traffic to the login page, and am using angularfire to authenticate. Here's all the relevant code. I know most of it is broken, but I'd like to get past this first. The problematic code is:

App.js

 app.run(['$rootScope', '$location', 'AuthenticatorService', function ($rootScope, $location, AuthenticatorService) {
        $rootScope.$on('$routeChangeStart', function (event) {

            if (AuthenticatorService.isLoggedIn) {
                console.log('DENY');
                event.preventDefault();
                $location.path('/login');
            }
            else {
                console.log('ALLOW');
                $location.path('/home');
            }
        });
    }]);
1

There are 1 best solutions below

0
On BEST ANSWER

You had missed couple of things in your code

  1. Your ng-app should be ng-app="BillingApp" instead of ng-app="App"
  2. You are missing $rootScope reference in service DI array.

Code

auth.service('AuthenticatorService', [ '$firebaseAuth', '$rootScope',//<--added this
    function($firebaseAuth,$rootScope) {

Plunkr Here