🐛 fix undefined choice

This commit is contained in:
Baptiste Lemoine 2019-10-03 11:27:25 +02:00
parent 49494236cf
commit 1074d219dd

View File

@ -1,5 +1,4 @@
import {Component, Input} from '@angular/core'; import {Component, Input} from '@angular/core';
import {environment} from "../../environments/environment";
interface VoteChoice { interface VoteChoice {
votesCount: { votesCount: {
@ -8,8 +7,8 @@ interface VoteChoice {
maybe: number maybe: number
notAnswered: number notAnswered: number
}; };
text: string; text?: string;
date: Date; date?: Date;
answer: 'yes' | 'no' | 'maybe' | null; answer: 'yes' | 'no' | 'maybe' | null;
simpleAnswer: boolean; // enable if we display only a togglable "yes" simpleAnswer: boolean; // enable if we display only a togglable "yes"
} }
@ -25,17 +24,21 @@ interface VoteChoice {
}) })
export class VoteChoiceComponent { export class VoteChoiceComponent {
@Input() choice: VoteChoice; @Input() choice: VoteChoice = {
date: new Date(),
text: 'description ',
votesCount: {
yes: 0,
no: 0,
maybe: 0,
notAnswered: 0
},
simpleAnswer: false,
answer: null
};
constructor() { constructor() {
if (!environment.production) {
// demo content for dev env
this.choice = {
date: new Date(),
text: 'description ',
simpleAnswer: false
}
}
} }
setAnswserTo(newAnswer: 'yes' | 'no' | 'maybe' | null) { setAnswserTo(newAnswer: 'yes' | 'no' | 'maybe' | null) {