0
votes

I am using Ionic2 with AngularFire2 and Firebase. I have a list/Array under a node in Firebase. The items are added with push() function. Following is the structure.

node:
     -KhPSh52vq2m23le1qZ5: "value1"
     -KhPShqhHDVuxeUbryT7: "value2"
     -KhPSijWf_EuwmCHPJjv: "value3"

Now I need to query one item from the list and delete it. I am doing the query with the following code and getting correct FirebaseListObservable.

this.af.database.list(`node`, {
        query:{
          orderByValue: true,
          equalTo: 'value1'
        }
      });

After this how to remove/update this single item from the list

1

1 Answers

2
votes

The list observable exposes several methods for saving and removing items. You should call remove, passing the key of the item to be removed:

let list = this.af.database.list('node', {
  query:{
    orderByValue: true,
    equalTo: 'value1'
  }
});

// Query the list for the purposes of this example:
list.first().subscribe((items) => {

  // Remove the matching item:
  if (items.length) {
    list.remove(items[0].$key)
      .then(() => console.log('removed ' + items[0].$key))
      .catch((error) => console.log(error));
  }
});