HttpInterceptor无法与angularfire2/Firestore API调用一起使用.任何解决方法? [英] HttpInterceptor not working with angularfire2/Firestore API calls. Any workaround?

查看:75
本文介绍了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 ... .),但不会成功.

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.

由于未使用@ angular/common/http/HttpClient,因此请求没有越过拦截器.

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

有没有解决方法可以在这些API调用上集成Angular Interceptor功能?

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

谢谢

推荐答案

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

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

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

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

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

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

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

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

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

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.

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

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

component.ts

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

component.html

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

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

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