I want to count how many students there are in a group

https://gyazo.com/458395bd24fee3bd8e868bd8973b3073 This is the JSON
https://gyazo.com/d951c7ea1d40f8001293963f25f78745 These are the cards generated from the JSON
In the card you can see the student and “groep” is which group he is in. I want to count all the students in a certain group. Example: 8 students groep 3 and I want to show that in a card.

Thanks in advance!

Loop through all items, for each one add 1 to an array with the groups. At the end you have an array with all groups and the number of students in it that you can use.

Can you show me please :frowning:

        <ion-item ng-repeat="item in items|groupBy:'groep'">
            Students : {{item.length}}

you can use the groupBy

That doesnt work for me. Runtime Error
Error in ./Page2 class Page2 - caused by: Cannot read property ‘length’ of undefined

this my data its work fine just change your array to a $scope variable

Typescript Error
Cannot find name ‘$scope’. and where do you define it

He use Angular 2 i think :wink:

1 Like

are you using angular 2 my example is for angular 1 only?

Yes i use angular 2 :slight_smile:

This should help you: http://stackoverflow.com/questions/37248580/how-to-group-data-in-angular-2

Do you have something similar with a for loop or something because I have never worked with pipe and I dont know what to change and what to do… I’m sorry for being annoying but I really want to know it.

Look at this example: https://angular.io/docs/ts/latest/guide/pipes.html

Pipes are really easy to use

Thank you. I’ll try my best!