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
2 Answers
Reset to default 10Use { 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
版权声明:本文标题:javascript - What can I replace the tap method with in my Angular app? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743946488a2566502.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论