javascript - 离线时停止监听 AngularFireAuth
问题描述
在我的 Angular 应用程序上,我使用它来了解状态(来源:https ://medium.com/@balramchavan/detecting-internet-connection-status-in-angular-application-ng-connection-service-1fa8add3b975 )
constructor(private connectionService: ConnectionService) {
this.connectionService.monitor().subscribe(isConnected => {
if (isConnected) {
// ONLINE
}
else {
// OFFLINE
}
})
}
对于我的 firebase 存储库,为了避免控制台错误泛滥,我有:
constructor(
protected afs: AngularFirestore,
protected connectionService: ConnectionService,
protected collectionName: string,
) {
this.connectionService.monitor().subscribe(status => {
if (status) {
afs.firestore.enableNetwork();
}
else {
afs.firestore.disableNetwork();
}
})
}
但我没有找到对 Auth Firebase 服务执行相同操作的方法:
constructor(
private angularFireAuth: AngularFireAuth,
protected connectionService: ConnectionService,
) {
this.connectionService.monitor().subscribe(status => {
if (status) {
angularFireAuth.//Start listening
}
else {
angularFireAuth.//Stop listening
}
})
}
所以我多次收到此错误:
发布https://securetoken.googleapis.com/v1/token?key=XXX net:: ERR_INTERNET_DISCONNECTED
你知道怎么处理吗?
谢谢
解决方案
推荐阅读
- python - 如何为分散在磁盘和每个文件中的数据正确定义 Pytorch 数据集和数据加载器?
- opencv - 获取 TypeError:找不到所需的参数“rec”(位置 2)
- datetime - FAGL_ACCOUNT_ITEMS_GL_API 在 I_POSTING_DATES 范围内不返回任何数据
- c++ - C++ ifstream 在末尾读取一个不存在的换行符
- python - pip install openpyxl - ModuleNotFoundError:没有名为“et_xmlfile”的模块
- scala - 如何将任务依赖项从另一个插件添加到我的 SBT 插件?
- javascript - 尝试使用 textinput 搜索某些内容后,Flatlist 数据消失
- c++ - 确定指向 const 的指针是否指向 const 对象?
- algorithm - 动态规划 - 减少工作能力的中断调度问题
- java - iOS 和 Android 上的等效加密和解密