【问题标题】:AngularFire2 Memory Leak after updating list更新列表后的AngularFire2内存泄漏
【发布时间】:2018-04-15 22:42:15
【问题描述】:

我正在尝试在单击按钮后更新 firebase 中的列表(增加列表中的值),但是,每当我单击按钮时,除非我关闭页面选项卡,否则该值会不断增加而不会停止。

onRecipeUpvote(recipe: Recipe)
{
    // get list with -> name: recipe.name
    let listRecipe = this.ngFireDB.list<Recipe>('/recipes', ref => ref.orderByChild('name').equalTo(recipe.name));

    listRecipe.snapshotChanges().map(actions => {
      return actions.map(action => ({ key: action.key, ...action.payload.val() }));
    }).subscribe(items => {
      return items.map(item => {
        // Increment its current upvotes by 1
        listRecipe.update(item.key, { upvotes: item.upvotes + 1 });           
      });
    });  
}

【问题讨论】:

    标签: angular typescript rxjs angularfire2 angularfire5


    【解决方案1】:

    功能完成后尝试手动退订。

    【讨论】:

    • 取消订阅不起作用,但是,我通过只允许一次投票解决了这个问题,因为内存泄漏发生在两次投票之后(我仍然不知道为什么)。
    猜你喜欢
    • 2013-10-13
    • 1970-01-01
    • 2011-12-24
    • 2017-03-01
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多