Summarizing the expenses by categories
Getting back to our application, as we want to create a graph showing the summary of expenses for each category, we will first need to calculate the total expense made under each category.
We will start by creating a function within our factory service that will total up the expenses for a category name that is passed to it.
Open up the app/js/services.js
file, and add the following function within the return {}
section of the expService
factory:
getCategoryTotal: function(category) { var categoryTotal = 0; var prefixLength = prefix.length; Object.keys(localStorage) .forEach(function(key) { if (key.substring(0, prefixLength) == prefix) { var item = localStorage[key] item = JSON.parse(item) if (item.category ...
Get AngularJS Web Application Development Blueprints now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.