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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/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
Angularjs 使用auth http拦截器广播登录确认_Angularjs_Forms Authentication_Facebook Login_Angular Http Interceptors_Angular Http Auth - Fatal编程技术网

Angularjs 使用auth http拦截器广播登录确认

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

我正在使用AuthHTTP拦截器来广播登录确认。我有一个main.html,用来检查用户是否登录

<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();
      });
    };