I'm trying to update a list (increment a value in the list) in firebase after a button is clicked, however, whenever I click on the button that value keeps incrementing without stopping unless I close the page tab.
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 });
});
});
}
Try manually unsubscribing the Subscription after the function completes.