tap

noun

say it: “TAP” /tæp/

An RxJS operator that does something with each value, such as saving it, and passes it on unchanged.

What is tap in Angular?

tap — An RxJS operator for side effects: it runs a function with each value going through an Observable, such as saving a token, and passes the value on unchanged.

login(form: LoginForm) {
  return this.http.post<LoginResult>('/api/login', form).pipe(
    tap(result => localStorage.setItem('token', result.token)),
  );
}

In a sentence

  • “tap saves the token to local storage as the login response passes by.”

Level: Journeyman · More Angular terms at this level

Updated