angularfire, remove method returns 'Invalid record; could not find key', what should it be happenning?

你说的曾经没有我的故事 提交于 2019-12-11 13:06:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!