2014-09-11 3 views
0

Ionic Mobile Framework를 사용하여 처음 로그인 페이지가 완성되고 Angular JS를 새로 습득했습니다. 로그인 페이지가 시작되면 세션이 만료되지 않은 경우에만 홈페이지로 이동하려고합니다. 그렇지 않으면 우리는 로그인 페이지로 가고 싶습니다. 로그 아웃 "노래"화면/상태와 로그인 화면/상태 사이에서 앞뒤로 잘 돌아가지만 한 가지 문제가 있습니다.Ionic : 각도 조절기가 앱 시작시 실행되지 않습니다.

앱이 부팅되면 노래 상태 또는 "집"페이지로 이동하지만 해당 상태에 대한 컨트롤러 코드는 실행되지 않습니다. 컨트롤러 코드에서 웹 사이트의 경로를 클릭하여 세션이 여전히 활성 상태인지 확인합니다. 그렇다면 JSON을 반환합니다. 그렇지 않으면 내 authInceptceptor가 인계 받아 상태를 로그인으로 전환합니다.

최종선은 컨트롤러가 앱을 시작할 때 실행되지 않아 내가 얼마나 많은 인터넷 검색을하는지 알 수없는 이유입니다. 다음은 몇 가지 코드 예제입니다.

.run(function($ionicPlatform, $cordovaSplashscreen, localstorage, $state) { 

    setTimeout(function() { 
    $cordovaSplashscreen.hide() 
    }, 1500) 

    $ionicPlatform.ready(function() { 
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 
    if(window.StatusBar) { 
     // org.apache.cordova.statusbar required 
     StatusBar.styleDefault(); 
    } 

    if(localstorage.get('subdomain') == undefined || 
     localstorage.get('subdomain') == 'null' || 
     localstorage.get('subdomain') == null || 
     localstorage.get('subdomain') == 'undefined' || 
     localstorage.get('subdomain') == "") 
    { 
     $state.go('subdomain'); 
    } 
    else 
     $state.go('songs'); 

    }); 
}) 



.config(function($stateProvider, $urlRouterProvider, $httpProvider) { 
    $urlRouterProvider.otherwise("/songs"); 

    $stateProvider 
    .state('login', { 
     url: "/login", 
     templateUrl: "templates/login.html", 
     controller: 'LoginCtrl' 
    }) 
    .state('subdomain', { 
     url: "/subdomain", 
     templateUrl: "templates/subdomain.html", 
     controller: 'SubdomainCtrl' 
    }) 
    .state('songs', { 
     url: "/songs", 
     templateUrl: "templates/songs.html", 
     controller: 'SongsCtrl' 
    }) 

    $httpProvider.interceptors.push('authInterceptor'); 

}); 

// register the interceptor as a service 
.factory('authInterceptor', function($q, $injector) { 
    return { 
    // optional method 
    'responseError': function(rejection) { 
     if(rejection.status == 0 || rejection.status == 403){ 
     $injector.get('$state').transitionTo('login',null,{ reload: true, inherit: true, notify: true }); 
     if(rejection.config.url.indexOf('login') > -1){ 
      navigator.notification.alert("Invalid username or password.", function(){}, "Login Failed"); 
     } 
     } 

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

.controller('SongsCtrl', function($scope, $state, user) { 

    user.check(); //Resource that hits route on server 

    $scope.logout = function() 
    { 
    user.logout(); 
    $state.go('login'); 
    } 
}) 

감사합니다. James

답변

0

문제는 요격기가 처리 할 수 ​​없었던 잘못된 서버 응답과 컨트롤러가 시작시 작동하지 않았는지 알 수없는 나쁜 디버깅 도구의 조합이었습니다.

관련 문제