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

Commit 520a062

Browse files
author
Jacob Wenger
authored
Added docs for $resolved and changelog for upcoming 2.1.0 release (#874)
* Added docs for $resolved and changelog for upcoming 2.1.0 release * Improved documentation for $resolved
1 parent a103a60 commit 520a062

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feature - Added `$resolved` property to `$firebaseArray` and `$firebaseObject` to get synchronous access to the loaded state.

docs/reference.md

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [`$bindTo(scope, varName)`](#bindtoscope-varname)
1212
* [`$watch(callback, context)`](#watchcallback-context)
1313
* [`$destroy()`](#destroy)
14+
* [`$resolved`](#resolved)
1415
* [`$firebaseArray`](#firebasearray)
1516
* [`$add(newData)`](#addnewdata)
1617
* [`$remove(recordOrIndex)`](#removerecordorindex)
@@ -22,6 +23,7 @@
2223
* [`$ref()`](#ref-1)
2324
* [`$watch(cb[, context])`](#watchcb-context)
2425
* [`$destroy()`](#destroy-1)
26+
* [`$resolved`](#resolved-1)
2527
* [`$firebaseAuth`](#firebaseauth)
2628
* Authentication
2729
* [`$signInWithCustomToken(authToken)`](#signinwithcustomtokenauthtoken)
@@ -174,8 +176,8 @@ obj.$save().then(function(ref) {
174176

175177
### $loaded()
176178

177-
Returns a promise which is resolved when the initial object data has been downloaded from the database.
178-
The promise resolves to the `$firebaseObject` itself.
179+
Returns a promise which is resolved asynchronously when the initial object data has been downloaded
180+
from the database. The promise resolves to the `$firebaseObject` itself.
179181

180182
```js
181183
var obj = $firebaseObject(ref);
@@ -288,6 +290,32 @@ unwatch();
288290
Calling this method cancels event listeners and frees memory used by this object (deletes the
289291
local data). Changes are no longer synchronized to or from the database.
290292

293+
### $resolved
294+
295+
Attribute which represents the loaded state for this object. Its value will be `true` if the initial
296+
object data has been downloaded from the database; otherwise, its value will be `false`. This
297+
attribute is complementary to the `$loaded()` method. If the `$loaded()` promise is completed
298+
(either with success or rejection), then `$resolved` will be `true`. `$resolved` will be
299+
`false` before that.
300+
301+
Knowing if the object has been resolved is useful to conditionally show certain parts of your view:
302+
303+
```js
304+
$scope.obj = $firebaseObject(ref);
305+
```
306+
307+
```html
308+
<!-- Loading state -->
309+
<div ng-if="!obj.$resolved">
310+
...
311+
</div>
312+
313+
<!-- Loaded state -->
314+
<div ng-if="obj.$resolved">
315+
...
316+
</div>
317+
```
318+
291319

292320
## $firebaseArray
293321

@@ -461,8 +489,8 @@ list.$indexFor("zulu"); // -1
461489

462490
### $loaded()
463491

464-
Returns a promise which is resolved when the initial array data has been downloaded from the
465-
database. The promise resolves to the `$firebaseArray`.
492+
Returns a promise which is resolved asynchronously when the initial array data has been downloaded
493+
from the database. The promise resolves to the `$firebaseArray`.
466494

467495
```js
468496
var list = $firebaseArray(ref);
@@ -547,6 +575,32 @@ function compare(a, b) {
547575
Stop listening for events and free memory used by this array (empties the local copy).
548576
Changes are no longer synchronized to or from the database.
549577

578+
### $resolved
579+
580+
Attribute which represents the loaded state for this array. Its value will be `true` if the initial
581+
array data has been downloaded from the database; otherwise, its value will be `false`. This
582+
attribute is complementary to the `$loaded()` method. If the `$loaded()` promise is completed
583+
(either with success or rejection), then `$resolved` will be `true`. `$resolved` will be
584+
`false` before that.
585+
586+
Knowing if the array has been resolved is useful to conditionally show certain parts of your view:
587+
588+
```js
589+
$scope.list = $firebaseArray(ref);
590+
```
591+
592+
```html
593+
<!-- Loading state -->
594+
<div ng-if="!list.$resolved">
595+
...
596+
</div>
597+
598+
<!-- Loaded state -->
599+
<div ng-if="list.$resolved">
600+
...
601+
</div>
602+
```
603+
550604

551605
## $firebaseAuth
552606

0 commit comments

Comments
 (0)