Reputation: 1129
Using Angularfire, i create todoList. But i have a problem in updating items. I try this code
var obj = $firebaseObject(ref);
obj.name = $scope.todo.title ;
obj.$save()
.then(function(ref) {
ref.key() === obj.$id; // true
}, function(error) {
console.log("Error:", error);
});
How can i update only the selected item.
Upvotes: 1
Views: 119
Reputation: 598668
Note that you can also simply update the TODO item's title directly, without going through $firebaseObject()
:
ref.update({ title: $scope.todo.title });
The $firebaseObject()
and $firebaseArray()
services are great for binding the underlying data to Angular views, but to perform an update to the data you can just as easily take the more direct approach. Since AngularFire is built on top of the Firebase JavaScript SDK, they interoperate perfectly.
Upvotes: 1
Reputation: 6124
How about this?
var obj = $firebaseObject(ref);
obj.$loaded().then(function () {
obj.name = $scope.todo.title;
obj.$save()
.then(function (ref) {
ref.key() === obj.$id; // true
}, function (error) {
console.log("Error:", error);
});
});
You are trying to save it before it's been loaded.
Upvotes: 1