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가 만들어지지 않아서 더 이상 잡히지 않는 것 같습니다.이 작업을 통해 무언가를 깨뜨렸습니다. (오류 콘솔도 없습니다)
내 접근 방식은 이자형? - 조언 해주세요! 감사합니다