I have learnt angularJS for three days,but I have some questions during my study.
well,in the "Run Block":
angular.module("techNodeApp",["ngRoute"]).
run(function($window,$rootScope,$http,$location){
$http({
url:"/api/validate",
method:"GET"
}).success(function(user){
console.log("success");
$rootScope.me=user;
$location.path("/");
}).error(function(data){
console.log("error");
$location.path("/login");
});
$rootScope.logout=function(){
$http({
url:"/api/logout",
method:"GET"
}).success(function(){
console.log("I've logged out");
$rootScope.me=null;
$location.path("/login");
})
}
})
In the server(Node.js):
app.get("/api/validate",function(req,res){
console.log("I can hear you FE");
});
app.get("/ajax/validate",function(req,res){
var _userId=req.session._userId;
if(_userId){
Controllers.findUserById(_userId,function(err,user){
if(err){
res.json(401,{msg:err});
}else{
res.json(user);
}
})
}else{
res.json(401,null);
}
});
The first I enter the website I haven't log in,so I thought when the app start run.It must go to the page of "http://localhost:3000/login".But it went to "http://localhost:3000" and it can't print the string "I can hear you FE" in the cmd.