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

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

我正在尝试将所有未经授权的流量路由到登录页面,并使用 angularfire 进行身份验证。 Here's all the relevant code. 我知道大部分都坏了,但我想先解决这个问题。有问题的代码是:

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. 你的 ng-app 应该是 ng-app="BillingApp" 而不是 ng-app="App"
  2. 您在服务 DI 数组中缺少 $rootScope 引用。

代码

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

Plunkr Here