angular - 如何返回嵌套订阅?
问题描述
我有以下嵌套订阅,我需要返回内部订阅。我该怎么做呢?
public updateProfiles(){
this.afAuth.idToken.subscribe(idToken=>{
return this.httpClient.post<any>('https:example.com/getData',{
"token": idToken,
"np":"hzlNpV1239nOKRTcsVdPG",
"cp":"M6nKYrSjsnA9v34vfB8oD"
});
})
}
在调用模块中,我想 this.authService.updateProfiles.subscribe(()=>{do something});
解决方案
您应该使其可管道化。
updateProfiles() {
this.afAuth.idToken.pipe(
switchMap(idToken => this.httpClient.post(your stuff))
).subscribe(result => console.log(result))
}
推荐阅读
- sql - Maximo Where 条款 PM & JP
- javascript - 'new' 表达式,其目标缺少构造签名,隐式具有 'any' 类型
- c# - 我需要允许用户在 datagridview C# 中添加的所有三列复选框中仅选中一个复选框
- javascript - 使用javascript限制输入表单中的字符
- typescript - JSON字符串解析打字稿
- amazon-web-services - AWS - 负载均衡器在私有子集中托管服务器
- python - 扩展 pandas 列中的日期
- sql - 将 UNIX 格式的特定日期插入 TABLE
- java - 未找到模块 xxx,xxx 需要
- r - 如何找到具有文本列的一个条件的所有列的平均值