Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit b029f53

Browse files
committed
Use angular.from/toJson in angularFireCollection. Fixes #68
1 parent c9cf276 commit b029f53

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

angularFire.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,12 @@ angular.module("firebase").factory("angularFireCollection", ["$timeout",
350350
// equivalent of calling `push()` on a Firebase reference.
351351
collection.add = function(item, cb) {
352352
var ref;
353+
// Make sure to remove $$hashKey etc.
354+
var newItem = angular.fromJson(angular.toJson(item));
353355
if (!cb) {
354-
ref = collectionRef.ref().push(item);
356+
ref = collectionRef.ref().push(newItem);
355357
} else {
356-
ref = collectionRef.ref().push(item, cb);
358+
ref = collectionRef.ref().push(newItem, cb);
357359
}
358360
return ref;
359361
};
@@ -373,13 +375,8 @@ angular.module("firebase").factory("angularFireCollection", ["$timeout",
373375
collection.update = function(itemOrId, cb) {
374376
var item = angular.isString(itemOrId) ?
375377
collection[indexes[itemOrId]] : itemOrId;
376-
var copy = {};
377378
// Update all properties, unless they're ones created by Angular.
378-
angular.forEach(item, function(value, key) {
379-
if (key.indexOf("$") !== 0) {
380-
copy[key] = value;
381-
}
382-
});
379+
var copy = angular.fromJson(angular.toJson(item));
383380
if (!cb) {
384381
item.$ref.set(copy);
385382
} else {

angularfire.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)