Ionic 3比较输入数据和json数据不起作用

时间:2018-04-10 17:55:59

标签: ionic3

我是离子的新手,我想做一个简单的测验应用程序与不同的问题类型。 (顺便说一句,对不起我的坏事:-))

我对以下问题感到困惑:我有一个问题类型,竞争对手必须输入答案。当他/她单击按钮时,应将输入答案与json文件中的解决方案进行比较。

所以我的问题现在是输入答案与json文件的答案相比没有。我能做什么?

question.ts

answerInput: string;

  submitAnswer(answer, question) {
     console.log(this.answerInput);
     if (this.answerInput === question.answer) { 
         this.score = this.score + this.counter;
         this.nextSlide();
     }
     else {
         this.counter = this.counter - this.counterReduce;

    }
    this.counter = this.counter;
   }

question.html

<div *ngIf="question.questiontype == 'Input'">
    <ion-item>
        <ion-input name="answerInput" [(ngModel)]="answerInput"></ion-input>
    </ion-item>
    <ion-label>Your Answer: {{answerInput}}!</ion-label>
    <button ion-button round small(click)="submitAnswer(answer,question)">Look if its true!</button>

question.json

  {
  "questiontype": "Input",
  "questionText": "A Question like whatever??",
  "hinweis": "Du Depp weißt auch gar nix!",
  "answers": [{
    "answer": "330",
    "correct": true,
    "clicked": false
  }]
},

1 个答案:

答案 0 :(得分:0)

您的if条件错误:

if(this.answerInput === question.answer){

应该是

if(this.answerInput === question.answers.answer){