问题
I'm currently developing a webapp with angularjs and firebase, while I am able to save new records I am not able to remove a record using someReference.$remove(varkey); the promise returns: 'Invalid record; could not find key' but the same reference is able to save items normally. i trim spaces on the varkey but yet all seems to fail, I'm using bower dependency which version is "angularfire": "~0.8.0" according to bower.json
So far my code in my service is:
var testRef = new Firebase('https://test-list.firebaseio-demo.com/list'),
testRefArr = $firebase(testRef).$asArray();
console.log(testRefArr);
var testpromise = testRefArr.$remove('-JXdmpQbeCAEBl7I3YVO');
testpromise.then(function (response) {console.log(response);}, function (error) {console.log('err: '+error);});
this is a demo base from this post: AngularJS with AngularFire 0.5.0 - $remove item doesn't work but they seem to be using version 0.5.0 and im using 0.8.0. Any ideas?
回答1:
The AngularFireArray.$remove
method accepts either an item or an index, it does not accept an id.
So to remove an item for which you know the id, you have to look the item up first:
testRefArr.$remove(testRefArr.$getRecord('-JXdmpQbeCAEBl7I3YVO'))
来源:https://stackoverflow.com/questions/26027829/angularfire-remove-method-returns-invalid-record-could-not-find-key-what-sh