I am trying to create a delete function that will get the delete my object from the Firebase.
I have the following structure on FireBase:
recipes recipebooks recipesPerRecipebook
- id - id - recipebook_id
- id - id - recipe_id: true
What I want to do is when I click delete I want to remove the recipe_id
from recipes
and the remove it also from recipesPerRecipebook/${recipebook_id}
I created a function in my recipes.service.ts
deleteRecipe(recipe_id:string, recipebook_id:string) {
this.sdkDb.child('recipes').remove(recipe_id)
.then(
() => alert('recipe deletion requested !')
);
this.sdkDb.child('recipesPerRecipebook/${recipebook_id}').remove(recipe_id)
.then(
() => alert('recipe Association deletion requested !')
);
}
I then have this in recipeDetails.component.ts
delete() {
this.recipesService.deleteRecipe(this.recipe.$key, this.recipe.recipebook_id);
}
I get the following error:
error_handler.js:54 Error: Firebase.remove failed: first argument must be a valid function.
I have two questions, firstly and most importantly where am I going wrong. And secondly doing this.sdkdb.child(...
twice feels a bit wrong and cumbersome could I simplify this?