我正在Angular 6中处理MCQ。目前,每个问题都通过相同的方法进行验证(在每个按钮的一个按钮中,单击(click)=“ reponseValide(question)”)。我想用一个按钮来验证每个问题。 你能给我一些例子吗?
questionnaire.component.html
<h4>Repondez aux questions !</h4>
<div *ngFor="let question of questions">{{question.id}} - {{question.libelle}}
<button type="button" routerLink="/resultat" class="btn btn-success">Changer</button>
<button class="btn btn-danger">supprimer</button>
<div class="row text-left options">
<app-reponse [question]="question"></app-reponse>
</div>
</div>
<!-- <button type="button" routerLink="/resultat" class="center btn btn-primary">Valider</button> -->
Reponse.component.html
<div class="" *ngFor="let reponse of reponses">
<div class="reponse">
<label class="container">
<input type="checkbox" [(ngModel)]="reponse.bonne" /> {{reponse.libelle}}
</label>
</div>
</div>
<button (click)="reponseValide(question)" >Valider question</button>
Reponse.component.ts
reponseValide(question) {
this.questionnaireService.reponseValide(question).subscribe(retour => {
if (retour) {
console.log('OK');
} else {
console.log('KO');
}
});
}
questionnaire.service.ts
reponseValide(question: any) {
return this.http.post<any>(`${environment.apiUrl}question/reponsesValide`, question);
}
您将如何做?