1

I have a array in firebase created using the push() function.

I am trying to remove a specific value in that array.

var arr = $firebaseArray(ref.child('invoices').child('pending').child(coId));

arr.$loaded().then(function(){
    var index = arr.$getRecord(invoiceId);
    arr.$remove(index);
})

However, this is not working. I keep getting -1 for the var index. If there is an easier way to remove a value, with or without angularFire, I would be open to it.

Thanks!

1 Answer 1

1

I made a plunker for your case and it works:

var ref = new Firebase('https://benjaminsuch.firebaseio-demo.com/'),
    arr = $firebaseArray(ref.child('invoices'));

  arr.$loaded().then(function() {
    var index = arr.$getRecord('item123423');
    console.log('index', index);

    arr
      .$remove(index)
      .then(function() {
        console.log('item removed')
      })
      .catch(function(error) {
        console.log('error', error);
      });
  });

Maybe you provide us a plunker too with your code, so we can see whats going on.

Sign up to request clarification or add additional context in comments.

1 Comment

Does invoiceId actually have a value? Because -1 means there have been no results found.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.