0

My attempts at retrieving the value of a firebase record are failing. My JSON is as follows:

{
  "accounts" : {
    "-KRPSyO4B48IpBnHBTYg" : {
      "dateCreated" : "",
      "email" : "",
      "provider" : "",
      "userId" : ""
    }
  },
  "products" : {
    "-KUKRafaNurpFhGF4jQa" : {
      "name" : ""

    }
  },
  "total" : 1
}

I'm trying to return the value of "total". Here's the latest attampt:

var totals = firebase.database().ref('total').once('value', function(products) {});
    $scope.totalPosts = totals;

and my HTML:

<div class="card" ng-controller="myController">{{totalPosts}}</div>

All I'm getting is an empty {}. What am I doing wrong?

Thanks in advance!

1 Answer 1

1

Firebase queries are asynchronous, try this.

firebase.database().ref('total').once('value', function(products) {
  $scope.totalPosts = products.val();
});

Read and write Data

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately I'm still getting empty braces.. and this error: "TypeError: JSON.stringify cannot serialize cyclic structures"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.