通过angularfire删除只是一个项目 [英] remove just a item by angularfire
问题描述
我只是想删除一个项目,但我的code删除所有项目。
我不明白,无法找到另一种解决方案,
请帮忙
< DIV NG重复=(ID,数据)DATAS>
<DATAS $保存(数据)输入类型=文本NG模型=data.nameNG变化= />
<DATAS $保存(数据)输入类型=文本NG模型=data.ageNG变化= />
<一个NG点击=为removeItem(ID)>删除< / A>
< / DIV>
REF =新的火力地堡(FIREBASE_URL);
的authData = ref.getAuth();
OBJ = $ firebaseObject(REF);
。OBJ $删除(ID);
如果 FIREBASE_URL
指向您的列表(甚至是整个数据库),那么确实是你的code将删除该列表。这是正常现象。由于您使用 $ firebaseObject
,要求 $删除()
上,将删除的对象;在这种情况下,物品的整个列表。
要与 ID
只删除项目:
REF VAR =新火力地堡(FIREBASE_URL);
VAR项目= $ firebaseArray(REF);
项目$删除(项目$ indexFor(ID));
这是一个有点令人费解BTW,你可以很容易做的:
新火力地堡(FIREBASE_URL).child(ID),一个.remove();
这已经被问过,所以请成为搜友:
- Angularfire:删除项目(S)
- AngularFire用火力地堡的参考变量不起作用 从数组$删除项目
- AngularFire - 删除单个项目
- Delete在火力地堡单个项目与AngularJS
I just want to remove an item, but my code removes all the items. I don't understand and can't find another solution,
please help
<div ng-repeat="(id, data) in datas">
<input type="text" ng-model="data.name" ng-change="datas.$save(data)" />
<input type="text" ng-model="data.age" ng-change="datas.$save(data)" />
<a ng-click="removeItem(id)">delete</a>
</div>
ref = new Firebase(FIREBASE_URL);
authData = ref.getAuth();
obj = $firebaseObject(ref);
obj.$remove(id);
If FIREBASE_URL
points to your list (or even entire database), then indeed your code will delete that list. This is expected behavior. Since you're using $firebaseObject
, calling $remove()
on that will remove the object; in this case the entire list of items.
To remove only the item with id
:
var ref = new Firebase(FIREBASE_URL);
var items = $firebaseArray(ref);
items.$remove(items.$indexFor(id));
This is a bit convoluted btw, you can just as easily do:
new Firebase(FIREBASE_URL).child(id).remove();
This has been asked before, so please become friendly with search:
- Angularfire: Delete item(s)
- AngularFire $remove item from Array using a variable in Firebase reference does not work
- AngularFire - Remove Single Item
- Delete single item in Firebase with AngularJS
这篇关于通过angularfire删除只是一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!