AngularFire $remove item from Array using a variable in Firebase reference does not work

后端 未结 2 1051
慢半拍i
慢半拍i 2021-01-23 07:18

I\'ve been struggling with the following problem:

I\'m trying to delete a \'Post\' item from a Firebase Array with the $remove AngularFire method which I have implemente

相关标签:
2条回答
  • 2021-01-23 07:50

    The easiest way for me was to use this:

    var ref= new Firebase('https://Yourapp.firebaseio.com/YourObjectName');
    ref.child(postId).remove(function(error){
        if (error) {
        console.log("Error:", error);
      } else {
        console.log("Removed successfully!");
      }
    });
    
    0 讨论(0)
  • 2021-01-23 08:03

    The only way I'm able to remove the item is using a loop on the array we get from firebase.

    var ref= new Firebase('https://Yourapp.firebaseio.com/YourObjectName');
    var arr_ref=$firebaseArray(ref);
        for(var i=0;i<arr_ref.length;i++){
            if(key==arr_ref[i].$id){
                console.log(arr_ref[i]);
                arr_ref.$remove(i);
            }
        }
    
    0 讨论(0)
提交回复
热议问题