2015-02-02 1 views
0

서버에서 쿠키 세션 검사를 수행 할 수 있도록 사용자 응용 프로그램을 수동으로 부트 스트랩하고 사용자가 유효한 세션이있는 경우에만 부트 스트랩을 계속합니다.별도의 파일에서 모듈을 참조하는 응용 프로그램을 수동으로 부트하는 방법

코드 :

angular.module('ppMobi', []) 
      .controller('firstCtrl', function ($scope) { 
       $scope.loggedIn = true; 
       $scope.foo = "Session Valid"; 
      }); 

      angular.element(document).ready(function() { 
       var initInjector = angular.injector(["ng"]); 
       var $http = initInjector.get("$http"); 
       //This will return a promise on success or failure and provided user has a valid session we can then take them to the app 
       //that is manually bootstrap our app. 
       return $http.get("/session/GetSession.json").then(function (response) { 
        if (response.data.success) { 
         console.log("Session found!"); 
         angular.bootstrap(document, ["ppMobi"]); 
        } else { 
         window.location = "/login.html"; 
        } 
       }, function (errorResponse) { 
        console.error("Session not found!"); 
       }); 
      }); 

예상대로이 작동하지만, 지금은 별도의 파일로 모듈 \ 컨트롤러 정의를 이동하고 싶습니다. 이미이 시도하고 스크립트를 추가 한

그래서 지금은이 메인 LIB 포함 직후 파일에 포함

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"> 
     </script> 
     <script src="app/app.js"></script> 
     <script type="text/javascript"> 



      angular.element(document).ready(function() { 
       var initInjector = angular.injector(["ng"]); 
       var $http = initInjector.get("$http"); 
       //This will return a promise on success or failure and provided user has a valid session we can then take them to the app 
       //that is manually bootstrap our app. 
       return $http.get("/session/GetSession.json").then(function (response) { 
        if (response.data.success) { 
         console.log("Session found!"); 
         angular.bootstrap(document, ["ppMobi"]); 
        } else { 
         window.location = "/login.html"; 
        } 
       }, function (errorResponse) { 
        console.error("Session not found!"); 
       }); 
      }); 
     </script> 

응용 프로그램/

angular.module('ppMobi', []) 
.controller('firstCtrl', function ($scope) { 
    $scope.loggedIn = true; 
    $scope.foo = "Session Valid"; 
}); 

그러나 app.js 그 문서의 준비된 처리기가 더 이상 $ http가 만들어지지 않아서 더 이상 잡히지 않는 것 같습니다.이 작업을 통해 무언가를 깨뜨렸습니다. (오류 콘솔도 없습니다)

내 접근 방식은 이자형? - 조언 해주세요! 감사합니다

답변

0

OK, 그래서 난 내 자신의 질문에 대답해야 ...

그래서 지금은 원래 처음에 따라 내 주요 html 파일에 무엇을했다 난 그냥 내 app.js에 문서 준비 핸들러 코드를 이동

, 코드 스 니펫은 모두 내 app.js이고 라이브러리 포함 후 파일에 포함됩니다.

이 방법으로 stuctured 나를 위해 여전히 잘 작동하고있다

관련 문제