【发布时间】:2017-10-08 20:38:23
【问题描述】:
我正在尝试使用 rxJS 来处理来自 angular2 中的 http 请求的响应
这是代码:
isUserConfirmed(): boolean {
let result: boolean = false;
this.authService.isUserConfirmed().subscribe(
retrievedData => {
//if no errors from the server
if (retrievedData.success) {
//if the confirmed flag is true
if (retrievedData.payload){
result = true;
console.log("i"+result);
} else {
result = false;
}
} else {
this.showError(retrievedData.message);
}
},
error => {
this.showError(error);
});
console.log("o"+result);
return result;
},
showError(error) {
//...
}
编辑
当我运行它时,我得到这个输出:
ofalseitrue
这意味着在 suscribe 方法中将结果值设置为 true,但这不会改变返回的结果值。
我怎样才能设法从订阅块中返回值集?
【问题讨论】:
标签: angular typescript rxjs