From 428822b97a6d108df1d05e350700deb997fd84bf Mon Sep 17 00:00:00 2001 From: Lukas Kimpel <lukas.kimpel@mni.thm.de> Date: Fri, 16 Mar 2018 01:53:06 +0100 Subject: [PATCH] Add function that will prepare options data for rendering --- .../creator-choice-content.component.html | 4 ++-- .../creator-choice-content.component.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/creator-choice-content/creator-choice-content.component.html b/src/app/creator-choice-content/creator-choice-content.component.html index b7554136c..f68229833 100644 --- a/src/app/creator-choice-content/creator-choice-content.component.html +++ b/src/app/creator-choice-content/creator-choice-content.component.html @@ -13,7 +13,7 @@ <mat-header-cell *matHeaderCellDef>Answer</mat-header-cell> <mat-cell *matCellDef="let answer"> <!-- ToDo: Check ngModel --> - <mat-checkbox color="primary" [(ngModel)]="answer.correct" name="answer">{{ answer.answerOption.label }} is {{ answer.correct }}</mat-checkbox> + <mat-checkbox color="primary" [checked]="answer.correct" [(ngModel)]="answer.correct" name="answer">{{ answer.answerOption.label }} is {{ answer.correct }}</mat-checkbox> </mat-cell> </ng-container> @@ -40,7 +40,7 @@ </mat-form-field> <div fxLayout="column" fxLayoutAlign="center"> <button mat-button type="button" - (click)="addAnswer(answerIsCorrect.value, answerLabel.value, answerPoints.value)"> + (click)="addAnswer(answerIsCorrect.checked, answerLabel.value, answerPoints.value)"> Add Answer </button> </div> diff --git a/src/app/creator-choice-content/creator-choice-content.component.ts b/src/app/creator-choice-content/creator-choice-content.component.ts index 50ddc36b1..25ddb4f6c 100644 --- a/src/app/creator-choice-content/creator-choice-content.component.ts +++ b/src/app/creator-choice-content/creator-choice-content.component.ts @@ -32,7 +32,7 @@ export class CreatorChoiceContentComponent implements OnInit { new AnswerOption('Option 3', '20'), new AnswerOption('Option 4', '30') ], - [0, 1, 3], + [0, 2, 3], true); displayedColumns = ['label', 'points']; @@ -43,10 +43,13 @@ export class CreatorChoiceContentComponent implements OnInit { } ngOnInit() { + this.fillCorrectAnswers(); + } + + fillCorrectAnswers() { for (let i = 0; i < this.content.options.length; i++) { this.correctAnswers.push(new CorrectAnswer(this.content.options[i], this.content.correctOptionIndexes.includes(i))); } - console.log(this.correctAnswers); } submitContent() { @@ -63,6 +66,7 @@ export class CreatorChoiceContentComponent implements OnInit { if (isCorrect) { this.content.correctOptionIndexes.push(this.content.options.length); } + this.fillCorrectAnswers(); this.submitContent(); } } -- GitLab