Angular2在具有相同类的另一个函数中调用函数,并在第二个中使用第一个函数属性

时间:2017-07-10 13:35:53

标签: angular typescript

我在一个类中有两个函数,两个类都从API调用中获取数据。

这是第一个功能

getQuotes(){
    this.quoteService.getQuotes()
    .subscribe(
      quotes => {
        this.quotCode = this.quotes.BasicDetails[0].QuotCode;
        }
      });
}

第二功能

getOption(){
    this.quoteService.getOptions()
    .subscribe(
            options => {
     })
}

我想从第一个函数

获取此行的数据
this.quotCode = this.quotes.BasicDetails[0].QuotCode;

并且基于this.quotCode getOption()将有不同的参数传递并将获得差异。回应也。所以有必要在第二个函数中使用this.quotCode

我在getQuotes()

中呼叫constuctor()

任何人都可以帮帮我吗? 感谢

1 个答案:

答案 0 :(得分:1)

documentation year是您需要的运算符:这样,您将在第一个请求成功后执行第二个请求。

mergeMap