Angularjs 使用auth http拦截器广播登录确认
我正在使用AuthHTTP拦截器来广播登录确认。我有一个main.html,用来检查用户是否登录Angularjs 使用auth http拦截器广播登录确认,angularjs,forms-authentication,facebook-login,angular-http-interceptors,angular-http-auth,Angularjs,Forms Authentication,Facebook Login,Angular Http Interceptors,Angular Http Auth,我正在使用AuthHTTP拦截器来广播登录确认。我有一个main.html,用来检查用户是否登录 <div class="auth-tripdelta" ng-class="{'wrapper':locationFunction(),'wrapper2': !locationFunction() }"> <bus-search class="block"> </bus-search> <div class="container
<div class="auth-tripdelta" ng-class="{'wrapper':locationFunction(),'wrapper2': !locationFunction() }">
<bus-search class="block">
</bus-search>
<div class="container">
<div class="row">
</div>
</div>
<div ui-view></div>
<newsletter class="visible-sm visible-md visible-lg" ng-show="locationFunction()"></newsletter>
</div>
1) 但是,我没有获得任何console.log。我的代码有什么问题吗
2) 我是对的,登录确认只触发了一次,而不是几次破坏了我的登录会话???首先,我会使用
controller
而不是link
,因为ctrl
是预编译的,link
是后编译的,其次,您确定您在正确的范围内广播了事件,并且如果广播的事件
是相同的吗?我尝试了两个范围,但这似乎与在$rootScope
上广播没有什么区别。很抱歉,这个愚蠢的问题。但是你会在哪里广播呢?在我的指令中?在您当前正在广播事件的地方,它可能在authService.loginconconfirm()中代码>只需注入$rootScope
并执行$rootScope.$broadcast('event:auth loginconconfirm')
.directive('authTripdelta',function() {
return {
restrict: 'C',
link: function(scope ,elem, attrs ) {
scope.$on('event:auth-loginRequired', function() {
console.log('test1'); // todo modal call above
});
scope.$on('event:auth-loginConfirmed', function() {
console.log('test2');
});
}
}
});
<form class="form" name="form" ng-submit="login()" novalidate>
<div>
<a class="btn btn-facebook loginButton" href="/authenticate/facebook" >
<i class="fa fa-facebook"></i> Connect with Facebook
</a>
<a class="btn btn-google-plus loginButton" href="/authenticate/google">
<i class="fa fa-google-plus"></i> Connect with Google+
</a>
</div>
</form>
$scope.login = function() {
$http.post('/login').success(function() {
authService.loginConfirmed();
});
};