Kiran Kumar
Kiran Kumar

Reputation: 1600

Firebase: Delete a node

Need to delete entry trainName

Firebase DB

I tried the below code which didnt work for me.

var usersRef = new Firebase('https://hosurcabapp.firebaseio.com').child('user');delee
var clientInfo = $firebase(usersRef);
$scope.clientInfo = clientInfo.$asObject();
$scope.deleteClient = function(key) {
    clientInfo.$remove(key);
};

Kindly help since am new to Firebase

Upvotes: 2

Views: 724

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

You can not set a null value in Firebase, since Firebase treats null as an instruction to delete the node. To quote the docs:

Passing null to set() will remove the data at the specified location.

Since your application most likely uses the null to signal some specific condition, you should substitute another value to signal that condition:

ref.child('trainName').set('<unnamed>');

Update

If you want to delete a node, you can do:

usersRef.child(key).remove();

See also the documentation for the Firebase delete function.

Upvotes: 4

Related Questions