2017-11-09 9 views
0

3(1、2、3)のパラメータを持つ関数に対してObservableを返して、設定URLで置き換えます。例: http://www.example.com/status?a= {0} &b = {1} &c = {2}。Return複数のパラメータの値を置き換えるために観測可能か?

マイコード:

getLink(one string, two: string, three): Observable<any> { 
    return Observable.of([this.externalLinks['url'].replace('\{0\}', one), 
    this.externalLinks['url'].replace('\{1\}', two), 
    this.externalLinks['url'].replace('\{2\}', three)]); 
} 

私は複数の値を返すとパラメータを交換することはできませんよ。私は3つの値をすべて返す方法を知りたいと思いますし、設定URLを置き換えます。 私はそれは実際にはかなり簡単です(または、私はそれが間違っていました)...任意の手掛かりため

答えて

1

をいただければ幸いです。

getLink(one string, two: string, three): Observable<{ 
    url: string, 
    replacedUrl: string, 
    value1: string, 
    value2: string, 
    value3: string 
}> { 
    return Observable.of({ 
    url: this.externalLinks['url'], 
    replacedUrl: this.externalLinks['url'] 
     .replace(`{0}`, one) 
     .replace(`{1}`, two) 
     .replace(`{2}`, three), 
    value1: one, 
    value2: two, 
    value3: three, 
    }); 
} 

あなたの答えは次のようになります。あなたのタイムリーな助けを

this.myService.getLink('one', 'two', 'three').subscribe(obj => { 
    console.log(obj.url); // base URL 
    console.log(obj.replacedUrl); // your URL completed 
    console.log(obj.value1); // 'one' 
    console.log(obj.value2); // 'two' 
    console.log(obj.value3); // 'three' 
}); 
+0

感謝の男... – Maniram

関連する問題