在Routhangestart上的旋转器加载与身份验证库
-
21-12-2019 - |
题
我正在使用热毛巾角图书馆( https://github.com/johnpapa/ Hottowel-Angular-Bower )我从高级开发人员继承的项目上。
我也结合了Auth0的身份验证库以获得Angular。
我需要将一些路由限制为经过身份验证的用户。要做到这一点,我设置了一些路由属性。
限制为非经过身份验证用户的路由的isLogin: true
。
对于需要身份验证的路由,以及与那些没有的人相反的requiresLogin: true
。为了检查每个导轨上的这些属性,我使用$rootScope.$on('$routeChangeStart' function())
。
app.run(function ($rootScope, $location, auth, common, config) {
var getLogFn = common.logger.getLogFn,
log = getLogFn('auth handle'),
events = config.events;
$rootScope.$on('$routeChangeSuccess', function (e, nextRoute, currentRoute) {
if (nextRoute.$$route && nextRoute.$$route.settings && nextRoute.$$route.settings.requiresLogin) {
if (!auth.isAuthenticated) {
$location.path('/login');
log('User not authenticated');
}
}
if (nextRoute.$$route && nextRoute.$$route.settings && nextRoute.$$route.settings.isLogin) {
if (auth.isAuthenticated) {
$location.path('/');
log('User is authenticated');
}
}
})
});
.
现在,似乎这是干扰热毛巾附带的旋转功能。在shell.js中,我找到以下内容:
$rootScope.$on('$routeChangeStart',
function (event, next, current) { toggleSpinner(true); }
);
$rootScope.$on(events.controllerActivateSuccess,
function (data) { toggleSpinner(false); }
);
$rootScope.$on(events.spinnerToggle,
function (data) { toggleSpinner(data.show); }
);
.
偶然的是旋转器永远不会停止旋转(例如,VM.ISBUSY= TRUE,因为控制器永远不会激活并重置这个),我将如何解决这个问题?
解决方案
一个想法是您可以使用事件($广播)在取得联合国授权访问时通知,因此它由关闭旋转器的控制器接收。
其他提示
我尚未研究代码很长,但你不应该使用$routeChangeSuccess
来停止旋转器吗?
$scope.isViewLoading = false;
$scope.$on('$routeChangeStart', function() {
$scope.isViewLoading = true;
});
$scope.$on('$routeChangeSuccess', function() {
$scope.isViewLoading = false;
});
. 不隶属于 StackOverflow