1

で転送値は、私は
1. getToken2方法
2.このトークンとトークンを取得した観測可能を作成したいflatMap
3を割り当ててユーザデータを取得するだけで受信したのuserDataとトークン( flatMap経由で受け取った)をlocalStorageに転送
問題は、第2のマップ方法でトークンにアクセスできないことです。
だから私はそれにアクセスできるようにストリームでこのトークン値を転送することができます。RxJS:ストリーム

getCurrentUser2() { 
     return this.getToken2() 
     .flatMap((token) => this.http.get(this.URL + '/ROS/profile?token=' + token)) 
     .map((res) => res.json().data) 
     .map((response) => { 

      localStorage.setItem('currentUser', JSON.stringify({ 
       token:token, ,**want to access token value here** 
       userProfile: response 
      })); 
      localStorage.setItem('orgId', response.structure.id); 
      return this.toUser(response, '12'); 

     }); 
    } 

この問題を解決するために私に考えてください。
種類よろしく

答えて

2

flatmapまたはmergeMapresultSelectorと呼ばれるオプションのパラメータを有しています。

発信元(外部)排出量と内部観測可能排出量の値と指標に基づいて、排出量に値を生成する機能。この関数に渡される引数は次のとおりです。

outerValue:ソース
から来た値の「インデックス」:投影観察可能
outerIndexから来た値:ソース
innerValueから来た値 innerIndex:投影観察可能

return this.getToken2() 
     .flatMap((token) => this.http.get(this.URL + '/ROS/profile?token=' + token),(token,response,outerIndex,innerIndex) => [token,response.json().data])) 
     .map((response) => { 
     //response is an array with both outer output and inner output. 
      localStorage.setItem('currentUser', JSON.stringify({ 
       token:response[0], 
       userProfile: response[1] 
      })); 
      localStorage.setItem('orgId', response[1].structure.id); 
      return this.toUser(response[1], '12'); 

     }); 
+0

からの値の「インデックスが」偉大な解決策のためにありがとうございました。本当に助けになりました! –

関連する問題