[英]How to get value inside the subscription in angular without using async await
How do you extract the value inside the subscribe on angular. 如何提取角度订阅中的值。
I have this code: 我有以下代码:
async trackingInfo(trackingNumber) {
const foo = await this.userService
.trackOrderStatus(trackingNumber)
.subscribe((status) => {
console.log(status, 'stat');
return status;
});
console.log(foo, 'grrr');
}
foo
returns the subscription not the status
I know theres away not to use async await but i totally forgot. foo
返回订阅不是status
,我知道那里有走不使用异步的await但我完全忘了。 much appreciate the help. 非常感谢您的帮助。 thanks 谢谢
Assign it to something in the subscribe block: 将其分配给订阅块中的内容:
status: any;
trackingInfo(trackingNumber) {
const foo = this.userService
.trackOrderStatus(trackingNumber)
.subscribe((status) => {
console.log(status, 'stat');
this.status = status;
});
console.log(foo, 'grrr');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.