Search code examples
angularrxjsngrx

how to save value in rxjs before map


i have an odata result that looks like this

enter image description here

i want to pickup "value" from here and before that i want to save the @odata.count in localStorage or may be just log it.

  getAllBankAccounts(url: string): Observable<BankAccount[]> {
return this.http.get(url).pipe(map((res) => res['value']));
}

how can i return observale array that is in "value" property but store '@odata.count' before that. ?


Solution

  • You can use tap to tap into the value of an observable.

    getAllBankAccounts(url: string): Observable<BankAccount[]> {
      return this.http.get(url).pipe(tap(res=>console.log(res['@odata.count'])),map((res) => res['value']));
    }