$ templateRequest

时间:2018-06-14 12:57:47

标签: angularjs circular-dependency

我尝试在身份验证令牌过期时打开弹出窗口但实际上我无法理解为什么我会获得循环依赖...

  

发现循环依赖:$ templateRequest< - $$ animateQueue< - $ animate< - $$ interimElement< - $ mdDialog< - authInterceptor< - $ http< - $ templateRequest< - $ compile

它看起来像是在$ template request

我试图使用我创建的新工厂并使用$ injector.get(),但它实际上是相同的...这是对的,我没有我非常了解这个错误,并且我尽力填补这些漏洞......

app.factory("tokenExpired",["$mdDialog",tokenExpired]);

function tokenExpired($mdDialog){
  return {
    show : function(){
      $mdDialog.show({
        controller: TokenExpiredController,
        templateUrl: 'token_expired.html'
      });
    }
  }
}

function TokenExpiredController($scope){
  $scope.title = "Connection expired";
  $scope.button = "Reconnect";
  $scope.text = "Your connection is expired, please sign in again";
  $scope.Reconnect = function() {location.reload();}
}

app.factory("authInterceptor", authInterceptor);
authInterceptor.$inject = ["$q","$rootScope","$timeout","$mdDialog","$injector"];
function authInterceptor($q,$rootScope,$timeout,$mdDialog,$injector) {
  return {
    // Add an interceptor for any responses that error.
    'responseError': function (response) {
      // Check if the error is auth-related.
      if (response.status === 401 || response.status === 403) {
        $('#fail').html(response.statusText);
        $rootScope.show_fail_notification = true;
        $timeout(function(){
          $rootScope.show_fail_notification = false;
        }, 3000);

        $injector.get('tokenExpired').show;
      }

      return $q.reject(response);
    }
  };
}

0 个答案:

没有答案