I can get the overall count of a number of articles in a JSON array using the following:
Home.html
<div ng-controller="pfcArticleCountCtrl">Number of Articles {{articlecount.length}} items</div>
Controllers.js
// Count number of total articles
pfcControllers.controller('pfcArticleCountCtrl', ['$scope', 'pfcArticles', function ($scope, pfcArticles) {
$scope.articlecount = pfcArticles.query();
}]);
Services.js
// Articles by ID
pfcServices.factory('pfcArticles', ['$resource', function ($resource) {
return $resource('https://myrestcall.net/tables/articles/:articleID', { articleID: '@id' },
{
'update': { method:'PATCH'}
}
);
}]);
But I would also like to display the number of articles by category. Here is an example JSON return:
[
{
"id": "66D5069C-DC67-46FC-8A51-1F15A94216D4",
"articletitle": "artilce1",
"articlecategoryid": 1,
"articlesummary": "article 1 summary. "
},
{
"id": "66D5069C-DC67-46FC-8A51-1F15A94216D5",
"articletitle": "artilce2",
"articlecategoryid": 2,
"articlesummary": "article 2 summary. "
},
{
"id": "66D5069C-DC67-46FC-8A51-1F15A94216D6",
"articletitle": "artilce3",
"articlecategoryid": 3,
"articlesummary": "article 3 summary. "
},
{
"id": "66D5069C-DC67-46FC-8A51-1F15A94216D7",
"articletitle": "artilce4",
"articlecategoryid": 1,
"articlesummary": "article 3 summary. "
},
]
In this instance the overall count is 4, but for Category 1, it should be 2. I want to display this on a page as follows:
Category 1 (2) Category 2 (1) Category 3 (1)
Total Articles (4)
How do I count the number of articles by category?