diff --git a/src/app/participant-choice-content/participant-choice-content.component.html b/src/app/participant-choice-content/participant-choice-content.component.html index 295ef1677c000df77920fe4efbce34c1301661c7..b731b9397f64528f72a58473ea31e5af0fd77e0c 100644 --- a/src/app/participant-choice-content/participant-choice-content.component.html +++ b/src/app/participant-choice-content/participant-choice-content.component.html @@ -1,10 +1,10 @@ -<form> +<form (ngSubmit)="submitAnswer()"> <h1 class="mat-headline">{{ content.subject }}</h1> <p>{{ content.body }}</p> <mat-divider></mat-divider> <mat-list> - <mat-list-item *ngFor="let answer of content.options"> - <mat-checkbox color="primary">{{ answer.label }}</mat-checkbox> + <mat-list-item *ngFor="let answer of checkedAnswers"> + <mat-checkbox color="primary" [(ngModel)]="answer.checked" name="answer">{{ answer.answerOption.label }}</mat-checkbox> </mat-list-item> </mat-list> <button mat-raised-button color="primary">Send answer</button> diff --git a/src/app/participant-choice-content/participant-choice-content.component.ts b/src/app/participant-choice-content/participant-choice-content.component.ts index 365adb1b47b028a581eaadd4489098d2ffb5395c..1840583d16559ab0bd4dbd8e80d1dfe0e4e2673a 100644 --- a/src/app/participant-choice-content/participant-choice-content.component.ts +++ b/src/app/participant-choice-content/participant-choice-content.component.ts @@ -1,6 +1,17 @@ import { Component, OnInit } from '@angular/core'; import { ChoiceContent } from '../choice-content'; import { AnswerOption } from '../answer-option'; +import { ContentAnswerService } from '../content-answer.service'; + +class CheckedAnswer { + answerOption: AnswerOption; + checked: boolean; + + constructor(answerOption: AnswerOption, checked: boolean) { + this.answerOption = answerOption; + this.checked = checked; + } +} @Component({ selector: 'app-participant-choice-content', @@ -22,10 +33,29 @@ export class ParticipantChoiceContentComponent implements OnInit { ], [2, 3, 4], true); + checkedAnswers: CheckedAnswer[] = []; - constructor() { + constructor(private answerService: ContentAnswerService) { } ngOnInit() { + this.initAnswers(); + } + + initAnswers(): void { + for (const answerOption of this.content.options) { + this.checkedAnswers.push(new CheckedAnswer(answerOption, false)); + } + } + + submitAnswer(): void { + const selectedAnswers: number[] = []; + for (let i = 0; i < this.checkedAnswers.length; i++) { + if (this.checkedAnswers[i].checked) { + selectedAnswers.push(i); + } + } + // ToDo: Implement function in service + // this.answerService.addChoiceAnswer(selectedAnswers); } }