loginService.islogged()
上面的函数返回一个类似于"failed“的字符串。但是,当我尝试在它上面运行then函数时,它将返回错误
TypeError: Cannot read property 'then' of undefined
并且光标指示在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');
});
更新
下面是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;
});
}
我确信$checkSessionServer
会导致一个“失败”的字符串。没别的了。
发布于 2014-07-17 02:43:10
您需要将您的承诺返回给调用函数。
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
}
发布于 2018-02-14 18:08:40
TypeError:当使用AngularJS调用Django服务时,无法读取未定义的属性'then‘。
如果您正在调用Python服务,代码将如下所示:
this.updateTalentSupplier=function(supplierObj){
var promise = $http({
method: 'POST',
url: bbConfig.BWS+'updateTalentSupplier/',
data:supplierObj,
withCredentials: false,
contentType:'application/json',
dataType:'json'
});
return promise; //Promise is returned
}
我们使用MongoDB作为数据库(我知道这无关紧要。但如果有人使用MongoDB + Python (Django) + AngularJS进行搜索,结果应该会出现。
发布于 2021-11-18 02:51:20
在函数内部返回promise值
return new Promise((done, err) => {
......
})
https://stackoverflow.com/questions/24788171
复制相似问题