Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
[docs][database] - Update webapi queries to show error callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
KkevinLi committed Mar 7, 2019
1 parent 0475099 commit 31179aa
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions docs/DATABASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,25 @@ The link is for the iOS SDK, but it's the same for Android.
<summary>Web API</summary>

```js
const onValueEvent = result => {
if (result.error) {
console.log("Listener error: " + result.error);
} else {
console.log("Key: " + result.key);
console.log("key exists? " + result.exists());
console.log("Value: " + JSON.stringify(result.val()));
}
};
public doWebAddValueEventListenerForCompanies(): void {
const path = "/companies";
const onValueEvent = (result: firebase.DataSnapshot ) => {
// NOTE: we no longer check for result.error as it doesn't exist. Pass in an onError callback to handle errors!
console.log("value : " + result.forEach(datasnapshot => {
console.log(datasnapshot.key + " " + JSON.stringify(datasnapshot.val()));
}));
console.log("key exists? " + result.exists());
this.set("path", path);
this.set("key", result.key);
this.set("value", JSON.stringify(result.val()));
};

const onErrorEvent = (err: Error ) => {
console.log("Encountered an error: " + err);
};
firebaseWebApi.database().ref("/companies").on("value", onValueEvent, onErrorEvent /* Totally Optional */);
}

firebaseWebApi.database().ref("/companies").on("value", onValueEvent);
```
</details>

Expand Down

0 comments on commit 31179aa

Please sign in to comment.