I am using angularfire $add method to add basic js objects of the form {id:integer,name:name} Now, if I want to update a particular item (which usually has a firebase-assigned key like "-JEcA_f70efHbKi5js7j" or something, my impression is that I should use the $save method. Here is how I am trying to do this:
$scope.chosenColors = $firebase(myChosenColorsRef);
$scope.updateColor = function(data){ //data is a JS object like {id:'id',name:'name'}
if($scope.chosenColors.$getIndex().length>0){
var keys = $scope.chosenColors.$getIndex();
keys.forEach(function(key, i) {
if($scope.chosenColors[key].id!=data.id){//if id matches I want to update name
$scope.chosenColors[key] = {id:data.id,name:data.name}
$scope.chosenColors.$save[key];
return;
}
});
}else{
$scope.chosenColors.$add(data);
}
But this doesn't appear to have any effect on the firebase...any ideas what I am doing wrong?