2015-01-29 2 views
4

이것은 일반적인 문제입니다. 톤이 있지만 아무 것도 작동하지 않는 것 같습니다. 여기 내가하는 일이있다. 내 상태로 일부 동적 인 애니메이션을 원합니다. 기본적으로 로그인은 멋진 애니메이션을 실행하고 실제 인터페이스로 이동합니다. 지금, 나는이 같은 전망을 중첩 시작 :

$stateProvider 
     .state('login', { 
      url: '/login', 
      title: "Login", 
      views: { 
       "master": { 
        controller: "LoginController", 
        templateUrl: "/components/login/login.html", 
        authentication: false 
       } 
      } 
     }) 
     .state("logout", { 
      url: "/logout", 
      title: "Logout", 
      authentication: false 
     }) 
     .state('foo', { 
      url: '/', 
      controller: "HomeController", 
      views: { 
       "master": { 
        templateUrl: '/components/ui-views/masterView.html' 
       }, 
       "[email protected]": { 
        templateUrl: '/components/sidebar/_sidebar.html' 
       }, 
       "[email protected]": { 
        templateUrl: '/components/header/_header.html' 
       } 
      } 
     }) 
     .state('foo.inventory', { 
      url: '/inventory', 
      title: "Inventory", 
      views: { 
       "[email protected]": { 
        controller: "InventoryController", 
        templateUrl: "/components/inventory/inventory.html" 
       } 
      } 
     }); 

그래서 로그 아웃 리디렉션해야하지만이 걸리면이 실행되는 동안. 이 로그 아웃 상태에서 전혀 이동하지 않습니다.

function run($http, $rootScope, $cookieStore, $state, $templateCache, $timeout, AuthService, modalService, const) { 
     var timeout; 

     FastClick.attach(document.body); 
     $rootScope.globals = $cookieStore.get('globals') || {}; 

if ($state.current.name !== 'login' && !$rootScope.globals.guid) { 
      $state.go('login'); 
     } else if ($state.current.name == 'login' && $rootScope.globals.guid) { 
      $state.go('foo'); 
     } 

     $rootScope.$on('$stateChangeStart', function (event, next, current, fromState, fromParams) { 
      var authorizedRoles = next.level != undefined ? next.level : 1, 
       needAuth = next.authentication != undefined ? next.authentication : true; 

      if (needAuth) { 
       if (!AuthService.isAuthorized(authorizedRoles, true)) { 
        event.preventDefault(); 
        if (AuthService.isAuthenticated()) { 
         $rootScope.$broadcast(const.auth.notAuthorized); 
         $state.go('foo', {}); 
        } else { 
         $rootScope.$broadcast(const.auth.notAuthenticated); 
        } 
       } 
      } 

      if (next.name == 'logout') AuthService.logout($rootScope.globals); 
     }); 

} 

가 왜이 작동하지 않을 : 여기 나는 것을 처리하고있어 어떻게? 이 일이 잘된 것 같습니다. 그러나 $state.go('login')은 잘못된 값을 반환합니다.

누군가 올바른 방향으로 나를 인도 할 수 있거나 정확하게 무엇이 잘못되었는지 말해주십시오.

+0

그냥 시도하십시오 window.location.hash = "# login"; $ state.go ('login') 대신에. – Asik

+0

URL 끝 부분에 로그인 만 해시하고 필요한 작업을 수행하지 않습니다. –

+0

많은 부품이 누락되었습니다. $ rootScope.globals.guid 또는 ** if ** rootScope. $ on 이전에 호출 된 곳은 어디입니까? ... 가장 좋은 방법은 문제를 재현하기위한 것이거나 모든 것을 공유하는 것입니다. –

답변

7

문제는 $ state.go가 실행 중이므로이 주제에 대한 문서가 많지 않은 것입니다. $ state.go는 아직 초기화되지 않았으므로 실행되지 않습니다.

5

동일한 문제가있었습니다. 하이퍼 링크에 대해 ui-sref 속성이 어떻게 작동하는지 디버깅 한 후, $state.go이 코어 각도 -ui 라이브러리에서 $ timeout을 감싸는 것을 발견했습니다.

var transition = $timeout(function() { 
       debugger; 
       $state.go("app.authentication"); 
      }); 

아마도 같은 것을 시도해 볼 수 있습니다. (핵심 라이브러리에서의 UI (SREF) 이벤트 핸들러는 분명이 해킹이라고 언급하고 있습니다.)

+0

나를 괴롭혔다 –

1

只 需要 升级 UI 라우터 版本 就 可以 了, 见 连接 地址 : https://github.com/mattlewis92/angular-bluebird-promises/issues/11

당신이 UI로 업그레이드하는 경우 -router 0.3.2 실제로 고정되어 있습니다 : angle-ui/ui-router @ 66ab048

+0

다중 언어 게시물을 모니터링하기가 어렵 기 때문에 SO의 공식 언어는 영어입니다. 응답 내용을 영어로 번역했는지 확인하십시오. – afxentios

+0

업데이트 주셔서 감사합니다. –

0

내 응용 프로그램에서이 문제에 직면했습니다 $state.goui-view의 상태와 관련이 없으므로 , 당신은이 문제에 직면 해있다, 그래서 이것을 시험해보십시오 :

app.run(['$state', '$rootScope', '$timeout', 
function ($state, $rootScope, $timeout) { 

$timeout(function() { 
     $state.go('login'); 
    }); 
}]);