Reputation: 586
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!
Upvotes: 1
Views: 2074
Reputation: 609
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.
Upvotes: 1