Hello together,
I want to compare an input data with the right answer from the database. if it is the same value, the counter is counted down until it reaches 0. Otherwise, it goes straight to the next slide.
My problem is, that the ngModel data doesnt compare to the database data. it always counts down even if the correct answer has been entered, but the console logs the ngModel data input.
html:
<div *ngIf="question.questiontype == 'Input'">
<ion-item>
<ion-input name="answerInput" [(ngModel)]="answerInput"></ion-input>
</ion-item>
<br>
<ion-item><ion-label>Deine Antwort: {{answerInput}}</ion-label></ion-item>
<button ion-button round small (click)="submitAnswer(question)" [disabled]="isenabled">Schau obs richtig ist!</button>
</div>
ts:
ngOnInit() {
let localData = this.http.get('assets/data/schnitzeljagd.json').map(res => res.json().rallyes);
localData.subscribe(data => {
this.information = data;
this.route = this.information[0]["route"][0]; // rally/route/ort
});
}
submitAnswer(question) {
if (this.answerInput === question.answers.answer) {
console.log(this.answerInput);
this.score = this.score + this.counter;
this.nextSlide();
}
else {
this.counter = this.counter - this.counterReduce;
if (this.counter === 750){this.presentToast()}
if (this.counter === 500){this.presentToast2()}
if (this.counter === 0) {
this.isenabled = true;
this.nextSlide();
}
console.log(this.answerInput);
}
this.counter = this.counter;
}
json-file:
"rallyes": [{ "rallyQR": "",
"namerallye": "'",
"welcome": "",
"route": [{
"ortQR": "",
"Ortname": "",
"OrtBeschreibung": "",
"Zwischenscreen": "",
"questions": [
{"questiontype": "Input",
"questionText": "",
"hinweis": "",
"answers": [{
"answer": "330",
"correct": true,
"clicked": false
}]
}]
}
]
Maybe someone can help me