如何在Angular的另一个请求中使用订阅的数据

时间:2019-07-03 14:34:41

标签: angular angular6

我有发布请求,该请求将提交数据。提交数据后,我将收到包含已提交项目ID的响应。

我已将该ID分配给变量。

现在,我需要在另一个发布请求中使用该变量。

当我尝试时,我可以看到值为空白

 this.sharepointService.createItem().subscribe( (response : Response) => {
      this.lastItemCreatedId = response['d'].ID;  // latitemcreated is a variable
      console.log("Newly created Item ID :" + this.lastItemCreatedId)
    })

现在我需要在另一个请求中使用lastItemCreatedId

      let url = "_spPageContextInfo.webAbsoluteUrl"+"_api/web/lists/getByTitle('List')/items('"+this.lastItemCreatedId+"')/AttachmentFiles/add(FileName='abc.txt')"

 this.sharepointService.addAttachementstoItem(url).subscribe()

信息:以上两个是发帖请求

如何在另一个发布请求中使用lastItemCreatedID变量值?

1 个答案:

答案 0 :(得分:1)

由于两种方法都被一个接一个地调用,因此您应该使用RxJS的mergeMap运算符。

我们可以使用dfnew = pd.Dataframe() dfnew = df[['ID','Mtu','Enr']] for i in range(4): dftemp = df[['Ct_%i[Years]'%i]] dfnew.join(dftemp) mergeMap上的可观察对象映射到一个内部可观察对象,然后将其作为createItem()变量的一部分进行分配。然后,我们调用addAttachementstoItem()方法,并在下一行的subscribe()中返回可观察对象。

url