【发布时间】:2015-04-29 02:20:00
【问题描述】:
在对象上调用 angularfire 的 $bindTo() 后如何从 firebase 中删除对象。出于某种原因,调用 $bindTo() 似乎会从对象中删除 $remove() 函数。
例如,除非您注释掉 $bindTo 行,否则以下应用中的删除按钮不起作用。
JS
var app = angular.module('myApp', ['firebase']);
app.controller('myCtrl', MyCtrl);
function MyCtrl($scope, $firebaseObject) {
var self = this;
this.test = $firebaseObject(new Firebase('https://bindtoissue.firebaseio-demo.com/test'));
//if you comment out this line then the delete button will work.
this.test.$bindTo($scope, 'ctrl.test');
this.test.$loaded(function() {
self.test.one = 1;
self.test.two = 2;
self.test.three = 3;
});
}
MyCtrl.prototype.delete = function() {
//$remove is undefined
this.test.$remove();
}
HTML
<div ng-app="myApp" ng-controller="myCtrl as ctrl">
<button ng-click="ctrl.delete()">delete</button>
<pre>{{ctrl.test | json}}</pre>
</div>
【问题讨论】:
-
试试
this.test.ref().remove() -
ref 也未定义
-
是的,通过我已经想知道的代码。您绝对可以重建 ref 并在其上调用
remove(),但感觉应该有一种更简单的方法。我看看能不能挖点东西。感谢使用<pre>{{ctrl.test | json}}</pre>方法来记录值顺便说一句,我们正在努力推广这一点。 :-) -
是的,我找到了一些解决方法,例如重建 ref,但只是想知道最好的方法是什么。感谢您的调查
标签: javascript angularjs firebase angularfire