AngularJS $rootScope.authenticated resets?



当我从一个页面重定向到主页时,我的rootscope似乎重置了?

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

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>

因此,在成功登录后,我将rootScope设置为true,但当它执行$window.location.htm时,它会重置true,并再次设置为false。我需要通过加载后的响应或其他方式重新验证每个页面吗?

编辑:ngRoute

application.js

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

已尝试$location.path("/");$scope$apply();

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

还有

$timeout(function () {
                            $location.path("/");
                        });

$location不会更改页面&窗口刷新我的rootscope

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

最新更新