Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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$rootScope.authenticated重置?_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS$rootScope.authenticated重置?

Javascript AngularJS$rootScope.authenticated重置?,javascript,angularjs,Javascript,Angularjs,似乎当我从一个页面重定向到我的主页时,我的根范围重置了 以下是登录后的重定向代码: self.authUser = function() { LoginService.authUser($scope.inputEmail, $scope.inputPassword, 'inf') .then(function(d) { $rootScope.authentica

似乎当我从一个页面重定向到我的主页时,我的根范围重置了

以下是登录后的重定向代码:

self.authUser = function() {
                LoginService.authUser($scope.inputEmail, $scope.inputPassword, 'inf')
                        .then(function(d) {
                            $rootScope.authenticated = true;
                            $window.location.href = '/job';
                        }, function(errResponse) {
                            $scope.errorLogin = true;
                            $rootScope.authenticated = false;
                        });
            };
以下是主页的代码:

    <script src="<c:url value="/resources/js/application.js"/>"></script>
    <script src="<c:url value="/resources/js/service/main_service.js"/>"></script>
    <script
        src="<c:url value="/resources/js/controller/main_controller.js"/>"></script>
<title>Insert title here</title>
</head>
<body ng-app='application'>
<div class='container' ng-controller='MainController as ctrl'>
    <span ng-show='authenticated'>lllllllllllllllloloooooo</span>
    <button class="btn btn-lg btn-primary btn-block" ng-click='ctrl.authorize()'>Sign
            in</button>
            </div>
</body>
尝试 $location.path(“/”); $scope.$apply()

及 $window.location.assign('/job')


$location不更改页面&$window刷新我的rootscope

我实际上没有正确使用rootscope,nGroute也没有正确使用。

您使用的是html5还是基于哈希的路由?您使用的是哪种路由系统?角路线?用户界面路由器?您当前正在重新加载应用程序,这将重置状态。您需要正确使用路由以防止重新加载。@datasage我使用的是ngRoute
'use strict';

var App = angular.module('application', [ 'ngRoute', 'ngCookies' ]).config(
        [ '$routeProvider', function($routeProvider) {
            $routeProvider.when('/', {
                templateUrl : '/job/',
                controller : 'main_controller'
            }).when('/login', {
                templateUrl : '/job/login',
                controller : 'login_controller'
            }).otherwise({
                redirectTo : '/'
            });
        } ]);
$timeout(function () {
                            $location.path("/");
                        });