All data reading is an asynchronous process.
To read or write data from the database, you need an instance of
To read data at a path and listen for changes you add a listener for the
You can also attach these listeners to children to get specific updates when a particular value changes:
In your handler you will have access to a
DataSnapshot which represents the data
contained in the node at the time of the event:
You should also listen for the
VALUE_CHANGED_ERROR event at this point. It will
be dispatched when there is an issue retrieving the value. For example, a read can
fail if the client doesn't have permission to read from a Firebase database location.
When this event is dispatched the event will have the
fields populated with the details of the error.
In some cases you may want a callback to be called once and then immediately removed, such as when initializing a UI element that you don't expect to change. This is useful for data that only needs to be loaded once and isn't expected to change frequently or require active listening.
To this end you can use the
once( callback:Function ) method and provide a callback
function to handle the result.
once function takes a
Function as a parameter which will be called when the value
has been read. This function should have one parameter of type
Object which will be the
value of the read operation. This value may be
null if an error occurred.