Reputation: 434
I am trying to delete specific values from my firebase DB. I want to delete this entry from firebase:
What I tried so far is my button on how to trigger the delete button:
<div class="single-bfunctions"
*ngFor='let bfunc of liste'>
<b> Name: </b>{{bfunc.Name}} <br>
<b> Beschreibung: </b> {{bfunc.Descr}}<br>
<b> Key: </b> {{bfunc.$key}}
<button type="button" ng-click="deleteSth(bfunc.name)">Delete Item </button>
</div>
... and my delete-method:
deleteSth(name){
firebase.database().ref('/BFunctions/').child(name).remove();
}
As I am also pretty new to Angular I don't really what the solution could be. I appreciate your answers!
Upvotes: 0
Views: 3519
Reputation: 26
your button initialisation should look like this, becuase your bfunc.Key is not defined. As is see your bfunc.Name is your key in your database. If this is like that you can make your code as follow:
<button type="button" ng-click="deleteSth(bfunc.$key=bfunc.Name)">Delete Item
than just use:
deleteSth(key){
firebase.database().ref().child('/BFunctions/'+key+'/').remove();
}
:)
Upvotes: 1
Reputation: 890
Try using the ref object
<div class="single-bfunctions"
*ngFor='let bfunc of liste'>
<b> Name: </b>{{bfunc.Name}} <br>
<b> Beschreibung: </b> {{bfunc.Descr}}<br>
<b> Key: </b> {{bfunc.$key}}
<button type="button" ng-click="deleteSth(bfunc.$key)">Delete Item
</button>
</div>
and
deleteSth(key){
firebase.database().ref('/BFunctions/' + key).remove();
}
If that doesnt work check your console it could be related to permissions or something else
Upvotes: 1