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

Commit 32f9d96

Browse files
committed
Add method $getRef to $firebase objects, fixes #252
1 parent 9eacd1d commit 32f9d96

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

angularfire.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@
4343
if (input) {
4444
if (!input.$getIndex || typeof input.$getIndex != "function") {
4545
// input is not an angularFire instance
46-
if( angular.isArray(input) ) {
47-
// if input is an array, copy it
46+
if (angular.isArray(input)) {
47+
// If input is an array, copy it
4848
sorted = input.slice(0);
49-
}
50-
else if( angular.isObject(input) ) {
49+
} else if (angular.isObject(input)) {
5150
// If input is an object, map it to an array
5251
angular.forEach(input, function(prop) {
5352
sorted.push(prop);
5453
});
5554
}
56-
}
57-
else {
55+
} else {
5856
// input is an angularFire instance
5957
var index = input.$getIndex();
6058
if (index.length > 0) {
@@ -140,7 +138,7 @@
140138
var self = this;
141139
var object = {};
142140

143-
// Set the $id val equal to the firebase reference's name() function.
141+
// Set the $id val equal to the Firebase reference's name() function.
144142
object.$id = self._fRef.ref().name();
145143

146144
// Establish a 3-way data binding (implicit sync) with the specified
@@ -391,6 +389,11 @@
391389
return angular.copy(self._index);
392390
};
393391

392+
// Return the reference used by this object.
393+
object.$getRef = function() {
394+
return self._fRef.ref();
395+
};
396+
394397
self._object = object;
395398
self._getInitialValue();
396399

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.

tests/e2e/test_chat.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ casper.then(function() {
126126
}, "Testing if $add, $set, $save and $remove return a promise");
127127
});
128128

129+
casper.then(function() {
130+
this.test.assertEval(function() {
131+
if (_scope.messages.$getRef().toString() != _url) return false;
132+
if (!(_scope.messages.$getRef() instanceof Firebase)) return false;
133+
return true;
134+
}, "Testing if $getRef returns valid Firebase reference");
135+
});
136+
129137
casper.then(function() {
130138
this.test.assertEval(function() {
131139
var empty = function() {};

0 commit comments

Comments
 (0)