使用Firestore限制物品时出错 [英] Error when limiting items with Firestore

查看:58
本文介绍了使用Firestore限制物品时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Firestore时,我将执行以下操作:

When I use Firestore, and I do the following:

  • 我查询具有限制的项目列表.
  • 我从该列表中删除了一个项目,然后又删除了一个项目.
  • 其余项目开始消失(它们不会被删除,只是不会显示给已登录的用户).
  • 如果我清除缓存/cookie或使用隐身窗口,则会再次显示消失的项目,但是如果我再次删除另一个项目,则该用户也将消失.

我创建了一个重现错误的Stackblitz: https://stackblitz.com/edit/angular-yhbuma

I have created a Stackblitz reproducing the error: https://stackblitz.com/edit/angular-yhbuma

要重现该应用,您只需在app.module.ts中填写Firebase配置:

To reproduce the app you only have to fill the Firebase config in app.module.ts:

只需单击添加项目"就开始添加项目,直到您拥有足够的页面"数为止.然后在其中一个中单击DELETE,然后在另一个中单击...

Just start to add items clicking on ADD ITEM, until you have enough to have more than 1 "page". Then click on DELETE, in one, then in another one...

推荐答案

item.service函数中,getItems返回一个Observable,因此,在home组件中调用getItems()时,您无需取消订阅先前的订阅.当您将此方法调用3次时,就会导致这种情况,而您对此进行了3次观察,这可能会导致您的错误.尝试添加一些订阅处理程序,并在您调用下一个 https://stackblitz.com/edit/angular时退订-ldvhff

In item.service function getItems is returning an Observable, so when you call getItems() in home component you don't unsubscribe the previous subscription. This leads to situation when you have this method called 3 times, you watch 3 times for this which can leads to your error. Try to add some subscription handler and unsubscribe previous when you call next https://stackblitz.com/edit/angular-ldvhff

这篇关于使用Firestore限制物品时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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