Eze*_*wei 89 javascript promise angularjs
loginService.islogged()
Run Code Online (Sandbox Code Playgroud)
上面的函数返回一个像"失败"的字符串.但是,当我尝试运行然后函数,它将返回错误
TypeError: Cannot read property 'then' of undefined
Run Code Online (Sandbox Code Playgroud)
并且光标在connected
之前和之后指示.then
.
以下是完整功能:
var connected=loginService.islogged();
alert(connected);
connected.then(function(msg){
alert("connected value is "+connected);
alert("msg.data value is "+msg.data);
if(!msg.data.account_session || loginService.islogged()=="failed")
$location.path('/login');
});
Run Code Online (Sandbox Code Playgroud)
UPDATE
这是islogged()
功能
islogged:function(){
var cUid=sessionService.get('uid');
alert("in loginServce, cuid is "+cUid);
var $checkSessionServer=$http.post('data/check_session.php?cUid='+cUid);
$checkSessionServer.then(function(){
alert("session check returned!");
console.log("checkSessionServer is "+$checkSessionServer);
return $checkSessionServer;
});
}
Run Code Online (Sandbox Code Playgroud)
我确信这$checkSessionServer
会导致"失败"的字符串.而已.
The*_*One 120
您需要将您的承诺返回给调用函数.
islogged:function(){
var cUid=sessionService.get('uid');
alert("in loginServce, cuid is "+cUid);
var $checkSessionServer=$http.post('data/check_session.php?cUid='+cUid);
$checkSessionServer.then(function(){
alert("session check returned!");
console.log("checkSessionServer is "+$checkSessionServer);
});
return $checkSessionServer; // <-- return your promise to the calling function
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
217045 次 |
最近记录: |