Tap

tap() operator

Perform a side effect for every emission on the source Observable, but return an Observable that is identical to the source.

Returns a mirrored Observable of the source Observable, but modified so that the provided Observer is called to perform a side effect for every value, error, and completion emitted by the source. Any errors that are thrown in the aforementioned Observer or handlers are safely sent down the error path of the output Observable.

This operator is useful for debugging your Observables for the correct values or performing other side effects.

 /**
   * Get all my experiences
   */
  public getExperiences(): void {
    this.employeeExperienceService.getItems('Experience')
      .pipe(
        tap(x => console.log(x)),
        catchError(err => {
          return throwError(err);
        }),
        takeUntil(this.onDestroy$)
      )
      .subscribe(res => {
        if (res.length === 0) {
          this.emptyArray = true;
        }
        this.experienceList = res;
      });
  }

Last updated