首页 > 解决方案 > 获取特定的 Observable 值

问题描述

所以目前我正在尝试从此响应正文中检索monthlyFee 值。

标签: angulartypescriptrxjsangular8

解决方案


getCurrentPlan函数中设置响应类型:

      .subscribe((currentPlanResponse: CurrentPlan[]) => {
        let currentPlan: CurrentPlan[] = currentPlanResponse;
        console.log('monthlyFee: ', 
          currentPlan[0].planGroupMap.sharePlans.plans[0].monthlyFee);
      });

请记住,您正在获取一个数组(或嵌套数组),因此这取决于您要对最终结果做什么,但上面显示了谁获取嵌套值。

检查我根据您的代码制作的这个 StackBlitz:https ://stackblitz.com/edit/rxjs-aesbq2

我评论了您的代码的某些部分,以便不创建整个服务和 http 请求,但正如您所说,这不是您的实际问题。


推荐阅读