angular - 在http get请求Angular 6中返回字符串
问题描述
return
我的请求中有一些问题。
getTest(id: string): string {
let foo: string = '';
this.service.testProfile(id).subscribe(
response => {
foo = response.body.foo;
},
error => {
console.log(error);
}
)
return foo;
}
我想开始foo
我的回应。foo
然后只是返回 foo 的新值。一切正常,但没有结果,知道我做错了什么吗?
感谢
解决方案
我用 Promise 解决了
getTest(id: string): Promise<any> {
return new Promise((resolve,reject) => {
this.service.testProfile(id).subscribe(
response => {
foo = response.body.foo;
},
error => {
console.log(error);
}
)
}
)
}
谢谢大家 !
推荐阅读
- r - 现有因子的组水平
- java - 如何使用页面
使用 Spring WebClient 响应 - r - 我似乎无法从 arima 模型中获取我的预测数据以在 x 轴上绘制日期,或使用 ggplot2 进行绘制
- mocking - 如何发现当前的 LDAP 结构?
- php - 如何在php中以所需格式拆分字符串
- python - 没有从 opencv-python 拉普拉斯运算中得到预期的输出
- java - 在 javafx tabpane 的选项卡之间插入选项卡
- php - 如何使用 php laravel 代码将图像插入到 phpmyadmin
- audio - ffmpeg:仅映射(不同)特定语言的音频和字幕流
- javascript - 为什么在解析函数触发到 Firebase 时发生错误?