I have the values I need in an array after reducing them from another array but can't seem to figure out how to work with them in an ng-repeat?
var data = [{ ticketId: 1, Category: "Driver", CategoryID: 29, SubCategory:"Monitor", SubCategoryID: 31 }, { ticketId: 2, Category: "Driver", CategoryID: 29, SubCategory: "Monitor", SubCategoryID: 31 }, { ticketId: 3, Category: "Hardware", CategoryID: 11, SubCategory: "Monitor", SubCategoryID: 32 }, { ticketId: 4, Category: "Hardware", CategoryID: 11, SubCategory: "phone", SubCategoryID: 13 }],
count = data.reduce(function (r, a) {
r[a.Category] = r[a.Category] || {};
r[a.Category][a.SubCategory] = (r[a.Category][a.SubCategory] || 0) + 1;
return r;
}, {});
document.write('<pre>' + JSON.stringify(count, 0, 4) + '</pre>');
Example:
<div ng-controller="controller as vm">
<ul ng-repeat="t in vm.array">
<li>{{t.data}}</li>
</ul>
</div>
angular.module("app").controller("controller", function(){
var main = this;
main.getCategoriesCount = function () {
var data = main.openTickets;
var count = data.reduce(function (r, a) {
r[a.Category] = r[a.Category] || {};
r[a.Category][a.SubCategory] = (r[a.Category][a.SubCategory] || 0) + 1;
return r;
}, {});
main.array = count;
}
}