angularjs - adding values from firebase -


{    "-jc6dpvcnncafhnkxauu" : {        "amount" : 2,        "body" : "dsfsdvsd",        "from" : "angular"    },    "-jc6fwfxkenc0amyzss_" : {        "amount" : 2,        "body" : "massage",        "from" : "angular"    } } 

this example of data i'm trying parse through

i trying grab items , add "amount" values. example want total 4. want in angularjs i'm not sure how reference objects , add "amount" values.

one way (with firebase's web/javascript api):

var ref = new firebase('https://your.firebaseio.com/'); ref.on('value', function(snapshot) {     var total = 0;     snapshot.foreach(function(childsnapshot) {         total += childsnapshot.val().amount;     });    console.log(total); }); 

doing in angular not make different. unless share of your code/markup, hard see problem is.

hint: if having problems doing something, helps rid of extraneous technologies. if problem adding values in firebase, throw away other technologies first , solve problem firebase (as did above). if problem how display calculated value in angular, rid of firebase/angularfire/ionic , first figure out how display calculated value angular.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -