I'm displaying the results of a survey in Angular and struggling with manipulating the data structure and how to perform math on each column of the table.
Numerous responses to the same survey will be collected in the database and the code below is used to display a summary of all the responses in table form to the survey administrator.
Each question within the survey has three answers:
- rating of lesson (1 - 10 : number)
- rating of instructor (1 - 10 : number)
- comments (string)
An example of how this array of objects is structured is below.
[ <- Whole survey response
[ <- Question 1
{
question: "Introduction to Angular 4"
},
{
answer : 7
},
{
answer : 6
},
{
answer : 'Good lesson!'
}
],
[ <- Question 2
{
question: "Structure of an Angular 4 Application"
},
{
answer : 5
},
{
answer : 2
},
{
answer : 'Instructor went too quickly!'
}
]
]
I'm currently outputting this into a table using this:
<ng-container *ngFor="let result of results; let rNumber = index;">
<table>
<tr *ngFor="let answer of result; let qNumber = index;">
<td *ngFor="let singleanswer of answer" style="border: 1px solid #333">
{{singleanswer.answer}}
</td>
</tr>
<hr>
</table>
</ng-container>
Which gives me a table containing all the answers for each response in the database:
7 6 Good lesson!
5 2 Instructor went too quickly!
I need to be able to populate a table with ALL question 1 responses and then output another table with all the question 2 responses in it.
Furthermore, I need to create an additional row at the bottom with the mean of the numerical values.
==edit== Codepen available here: https://codepen.io/Taylorsuk/pen/NvzwaP (codepen seems flakey - forked from here)