Reputation: 1828
I have the following Firebase database:
I just want to retrieve a set of Accounts
records and later bind it with ng-repeat
as shown below:
<table>
<tr ng-repeat="account in accounts">
<td>{{ account.AccName }}</td>
<td>{{ account.AccStatus }}</td>
</tr>
</table>
I use the Automatic version of Firebase references and initialization as shown below, therefore no apiKey
and databaseURL
have been specified here:
<!-- update the version number as needed -->
<script defer src="/__/firebase/6.2.4/firebase-app.js"></script>
<!-- include only the Firebase features as you need -->
<script defer src="/__/firebase/6.2.4/firebase-auth.js"></script>
<script defer src="/__/firebase/6.2.4/firebase-database.js"></script>
<script defer src="/__/firebase/6.2.4/firebase-messaging.js"></script>
<script defer src="/__/firebase/6.2.4/firebase-storage.js"></script>
<!-- initialize the SDK after all desired features are loaded -->
<script defer src="/__/firebase/init.js"></script>
When I do a simple check on the snapshot
, it is always not exist (no runtime error whatsoever):
// ref("Accounts") is my root ref as shown in picture above
const accountsRef = firebase.database().ref("Accounts");
accountsRef.once("value").then(function (snapshot) {
if (snapshot.exists()) {
console.log(snapshot.val());
} else {
console.log("Snapshot not exist!");
}
})
I tried ref("/Accounts")
and ref("Accounts/")
but no luck. Sorry that I'm very new to Firebase real-time database. I just want to know:
Accounts
database table and bind it with ng-repeat
as shown above?OTK-001
is an unique account code for each record in the Accounts
table/collection.apiKey
and databaseURL
like the old way? (NOTE: Tried before, not working.)Any help will be appreciated, thanks in advance!
Upvotes: 1
Views: 71
Reputation: 376
Firestore querying is like the below
collection reference for firestore is
let collectionRef = firestore.collection('col/doc/subcollection');
Fetching the data is
async getAccountData() {
const snapshot = await firebase.firestore().collection('accounts').get()
return snapshot.docs.map(doc => doc.data());
}
Upvotes: 1