javascript - How to delete angularfire object after calling $bindTo -
how delete object firebase after calling angularfire's $bindto() on object. reason calling $bindto() seems remove $remove() function object.
for example delete button in following app doesn't work unless comment out $bindto line.
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 comment out line delete button 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 undefined this.test.$remove(); } html
<div ng-app="myapp" ng-controller="myctrl ctrl"> <button ng-click="ctrl.delete()">delete</button> <pre>{{ctrl.test | json}}</pre> </div>
note $bindto() not put synchronized object on scope, data. in case, have put synchronized $firebaseobject @ this.test, , bound data this.test.
note there no reason, in example, utilize $bindto(). can call $remove() without creating 3-way binding, useful making local changes object when don't want call $save() manually.
also, usage of $loaded incorrect here. when use $bindto(), you'll want use promise returns instead.
this.test.$bindto($scope, 'ctrl.test') .then(function() { self.test.one = 1; self.test.two = 2; self.test.three = 3; });
Comments
Post a Comment