Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS:Uncaught ReferenceError:$rootScope未在运行中定义_Javascript_Angularjs_Firebase_Angularjs Service_Angularfire - Fatal编程技术网

Javascript AngularJS:Uncaught ReferenceError:$rootScope未在运行中定义

Javascript AngularJS:Uncaught ReferenceError:$rootScope未在运行中定义,javascript,angularjs,firebase,angularjs-service,angularfire,Javascript,Angularjs,Firebase,Angularjs Service,Angularfire,我正在尝试将所有未经授权的流量路由到登录页面,并使用angularfire进行身份验证。我知道大部分都坏了,但我想先过一下这关。问题代码是: App.js app.run(['$rootScope', '$location', 'AuthenticatorService', function ($rootScope, $location, AuthenticatorService) { $rootScope.$on('$routeChangeStart', function (

我正在尝试将所有未经授权的流量路由到登录页面,并使用angularfire进行身份验证。我知道大部分都坏了,但我想先过一下这关。问题代码是:

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');
            }
        });
    }]);

您在代码中遗漏了一些内容

  • 你的
    ng app
    应该是
    ng app=“BillingApp”
    而不是
    ng app=“app”
  • 服务DI数组中缺少
    $rootScope
    引用
  • 代码

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

    auth.service('AuthenticatorService',['$firebaseAuth','$rootScope',//您在代码中遗漏了几件事

  • 你的
    ng app
    应该是
    ng app=“BillingApp”
    而不是
    ng app=“app”
  • 服务DI数组中缺少
    $rootScope
    引用
  • 代码

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