2017-07-10 4 views
0

APIコールからデータを取得するクラスに2つの関数があります。ここで同じクラスを持つ別の関数でAngular2関数を呼び出し、最初の関数を2番目に使用する

まず機能が

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.quotCodegetOption()は、渡すパラメータが異なり、diffを取得します。応答も。私は誰もが私を助けてくださいすることができgetQuotes()constuctor()

を呼んでいる?第二の機能に

this.quotCodeを使用する必要がありますか ありがとう

+0

@trichetricheここでお手伝いできますか? –

答えて

1

RXJSmergeMapが必要な演算子です。この方法では、最初のものが成功すると2番目のリクエストが実行されます。

this.quoteService.getQuotes().mergeMap(quotes => { 
    // Do whatever you need to do with quotes 
    return this.quoteService.getOptions() 
}).subscribe(options => { 
    // Do whatever you need with options 
}); 
+0

さて、試してみましょう –

+0

ありがとうございました –

+0

動作しますが、最初に読み込まれても 'getOptions'はまったく読み込まれません –

関連する問題