admin管理员组

文章数量:1356336

I have the following code as part of an http-interceptor:

handler(next, request) {
    return next.handler(request)
        .pipe(
            tap(
                (event) => {
                    if (event instanceof HttpResponse) {
                        this.spinnerService.requestEnded();
                    }
                },
                (error: HttpErrorResponse) => {
                    this.spinnerService.resetSpinner();
                    throw error;
                }
            ),
        );
}

It uses tap (line 4) which has been deprecated since Angular 8. How can I replace tap? The searched I've done have not helped me find an answer. Thanks.

I have the following code as part of an http-interceptor:

handler(next, request) {
    return next.handler(request)
        .pipe(
            tap(
                (event) => {
                    if (event instanceof HttpResponse) {
                        this.spinnerService.requestEnded();
                    }
                },
                (error: HttpErrorResponse) => {
                    this.spinnerService.resetSpinner();
                    throw error;
                }
            ),
        );
}

It uses tap (line 4) which has been deprecated since Angular 8. How can I replace tap? The searched I've done have not helped me find an answer. Thanks.

Share Improve this question edited Jun 8, 2022 at 13:22 isherwood 61.2k16 gold badges121 silver badges170 bronze badges asked Jun 8, 2022 at 13:04 MychMych 2,5634 gold badges40 silver badges70 bronze badges 1
  • 2 Pretty sure tap isn't deprecated., it's not marked as such in the docs: rxjs.dev/api/operators/tap. Can you share the full error? – Evan Trimboli Commented Jun 8, 2022 at 13:16
Add a ment  | 

2 Answers 2

Reset to default 10

Use { next, error } object

   tap({
       next: (event) => {
           if (event instanceof HttpResponse) {
               this.spinnerService.requestEnded();
           }
       },
       error: (error: HttpErrorResponse) => {
           this.spinnerService.resetSpinner();
           throw error;
       }
   })

I think tap is not deprecated, just the way of using tap is changed. You can try the following:

    updateHero(hero: Hero): Observable<any> {
  return this.http.put(this.heroesUrl, hero, this.httpOptions).pipe(
    tap(_ => this.log(`updated hero id=${hero.id}`)),
    catchError(this.handleError<any>('updateHero'))
  );
}

本文标签: javascriptWhat can I replace the tap method with in my Angular appStack Overflow