//Returns a promise of the total sum for each object.amount under a category getTotalAmountPromise(observable) { let totalAmount: number = 0; return new Promise(function(resolve, reject) { let count = 0; observable.$ref.ref.on('child_added', childs => { childs.ref.once('value', obj => { totalAmount += obj.val().amount; count++; let length = childs.numChildren(); if(count == length) { resolve(totalAmount); } }); setTimeout(() => { if (!(count == length)) reject(Error('Data rejected. Count: ' + count + ', Childs: ' + length)); }, 5000); }); }); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)