使用其他人的答案来创建具有可用问题的调查

I am trying to create a survey with yes/no question, I will have many questions, so I'd like to create an array with all the info and then run ngFor to display my questions.

It works perfectly. What I'd like to do now is to add a parameters to each of my question that allow me to specify if this question will be displayed depending on the answer of others questions. So in the array that followed, I'd like to add something into the condition of question id 1 like 'questions.id.answer == 'YES'', I know that this does not work questions.id.answer can not work but I think you gt the idea.

  questions = [
    {
      id:0,
      title: "Test 1 ?",
      answer: "",
      condition: ""

    },
    {
      id: 1,
      title: "Test 2 ?",
      answer: "",
      condition: ""
    },
    {
      id: 2,
      title: "Test 3 ?",
      answer: "",
      condition:""
    },
  ];

这是我的html文件:

  <ion-list *ngFor="let q of questions; let i = index">
    <ion-list-header>
      <ion-label id="sous_sous_titre" class='ion-text-center'>
        Q{{i}} - {{q.title}}
      </ion-label>
    </ion-list-header>
    <ion-radio-group
    (ionChange)="SelectedType($event,q.id)"
    ([ngModel])="q.answer"
    name="q.answer"
    >
      <ion-item >
        <ion-label>YES</ion-label>
        <ion-radio value="yes"></ion-radio>
      </ion-item>


      <ion-item >
        <ion-label>NO</ion-label>
        <ion-radio value="no"></ion-radio>
      </ion-item>


    </ion-radio-group>
  </ion-list>

  <ion-button (click)="onValidate()">Valider</ion-button>

这是我的.ts文件中的函数:

  SelectedType(event, id:number){
    console.log(id);
    this.questions[id].answer = event.detail.value;

  }

  onValidate(){
    console.log(this.questions);
  }

So basically, I'd like to add somewhere a *NgIf="" and inside this I could pass q.condition, but I have no idea what to put in the condition. I'd like to access the answer of a question with maybe something like q[i].answer == 'YES', but it does not work ...

评论