Alex Garulli
Alex Garulli

Reputation: 757

Firebase remove function do not work

I'm building an app with Firebase and AngularJS and I have a table with my users. From one of my view I want to create a form permit to delete users from the Firebase table . So I have a drop down menu with my users names and submit button.

I wrote a function to retrive the name of the user from the form and combine it with my url location of the user table, in fact the table has user name as id :

     $scope.Delete_user = function(name) {
          var testRef = new Firebase("https://alex-jpcreative.firebaseio.com/users")
          var newRef = testRef + '/' + name;
          $scope.removeUser(newRef);
      }

In this function I called the removeUser one that is a function I found in Firebase doc to delete a item from the table :

$scope.removeUser = function(ref) {
  ref.remove(function(error) {
 alert(error ? "Uh oh!" : "Success!");
 });
}

I can see the first function working fine pass the right name of users and combine it with the URL but then I have this error and it doesn't work:

TypeError: Object https://alex-jpcreative.firebaseio.com/users/Alex_dev_JPC has no method 'remove'

Upvotes: 0

Views: 2371

Answers (1)

matthewtole
matthewtole

Reputation: 3247

You need to use the child method to get the reference to the user object, rather than just appending the string to the end:

$scope.Delete_user = function(name) {
    var testRef = new Firebase("https://alex-jpcreative.firebaseio.com/users");
    var newRef = testRef.child(name);
    $scope.removeUser(newRef);
}

See the Firebase documentation for more details.

Upvotes: 2

Related Questions