AngularFire - 删除单个项目

tve*_*his 5 angularjs firebase angularfire pug

以下是我视图中的相关代码:

p(ng-repeat="t in todos")
input(
    type="checkbox",
    ng-model="t.done",
    ng-click="clearItem($event)"
    )
{{t.text}} done? {{t.done}}
Run Code Online (Sandbox Code Playgroud)

单击该复选框时,我希望todos从数据库中删除数组中的相应对象.

我的clearItem功能如下:

$scope.clearItem = function(event) {
        todoRef.remove($scope.t);
    }
Run Code Online (Sandbox Code Playgroud)

但是,这会删除我的数据库中的所有条目.我希望它只删除有问题的特定对象.反正我还能这样做吗?

tve*_*his 8

好吧,想通了.

循环使用时ng-repeat,请使用(id, t) in todos.这允许您id作为参数发送到ng-click函数,并且$scope.todos.$remove(id)工作得很好.