HttpInterceptor 不适用于 angularfire2/Firestore API 调用.任何解决方法? [英] HttpInterceptor not working with angularfire2/Firestore API calls. Any workaround?

查看:22
本文介绍了HttpInterceptor 不适用于 angularfire2/Firestore API 调用.任何解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

版本信息

角度:7/火力基地:5.7.3/AngularFire:5.1.1

我尝试在 angularfire2/Firestore API 调用上实现 HttpInterceptor(请求 URL:https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel?database=projects....) 没有成功.

请求没有穿过拦截器,因为没有使用@angular/common/http/HttpClient.

是否有任何解决方法可以在这些 API 调用中集成 Angular Interceptor 功能?

谢谢

解决方案

据我所知,AngularFire 是 Firebase SDK 的 Angular 友好包装器.

Firebase SDK 不使用 Angular Http Client,因此无法拦截来自 SDK 的 API 调用.

您想在什么用例中拦截 Firebase API 调用?

这是我如何实现一个简单的加载微调器的伪代码示例.

在启动 Firestore 操作的事件中,您可以将 isLoading 设置为 true,一旦您收到 Firestore 的响应,您就可以将 isLoading 设置为 fasle.

在您的模板中,您可以使用 *ngIf 显示加载微调器.

component.ts

this.isLoading = false;onEvent() {this.isLoading = true;this.angularFirestore.collection('test').doc('testId').set(data).订阅(成功 =>{this.isLoading = false;}错误 =>{控制台日志(错误);this.isLoading = false;});}

component.html

<加载旋转器>

Version info

Angular: 7 / Firebase: 5.7.3 / AngularFire: 5.1.1

I tried to implement HttpInterceptor on angularfire2/Firestore API calls (Request URL: https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel?database=projects....) without success.

The requests are not crossing the Interceptor as @angular/common/http/HttpClient is not used.

Is there any workaround to integrate the Angular Interceptor functionality on those API calls?

Thank you

解决方案

As far as i know AngularFire is a Angular friendly wrapper for the Firebase SDK.

The Firebase SDK does not use Angular Http Client so API calls from the SDK can not be intercepted.

For what use case do you want to intercept Firebase API calls?

Edit:

Here is a pseudo code example how i implement a simple loading spinner.

On the event which starts the Firestore operation you could set isLoading to true and as soon as you get the response from Firestore you could set isLoading to fasle.

In your template you could display a loading spinner with *ngIf.

component.ts

this.isLoading = false;

onEvent() {
    this.isLoading = true;
    this.angularFirestore.collection('test').doc('testId').set(data)
        .subscribe(
            success => {
                this.isLoading = false;
            }
            error => {
                console.log(error);
                this.isLoading = false;
            }
        );
}

component.html

<div *ngIf="isLoading">
    <loading-spinner>
</div>

这篇关于HttpInterceptor 不适用于 angularfire2/Firestore API 调用.任何解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆