I'm trying to pass the index from a ngFor to a my ts file without any success. I actually don't know how to do that. Can someone tell me how to pass the index value from the html to the ts file? I thought using a @Input would be te solution but nothing happen... Thanks.
My HTML:
<div *ngFor="let question of questions | async; index as i">{{question.libelle}}
<div class="row text-left options">
<div class="col-md-6" *ngFor="let reponse of reponses | async">
<div class="option">
<label class="" [attr.for]="reponse.id">
<input type="checkbox" [(ngModel)]="reponse.Selected"/>
{{reponse.libelle}}
</label>
</div>
</div>
</div>
{{i}}
</div>
My TS:
@Injectable()
@Component({
selector: 'app-java',
templateUrl: './java.component.html',
styleUrls: ['./java.component.sass']
})
export class JavaComponent implements OnInit {
@Input() i : any;
questions :any = [];
reponses :any = [];
constructor(private questionnaireService: QuestionnaireService) { }
ngOnInit() {
this.questions = this.questionnaireService.getQuestion();
this.reponses = this.questionnaireService.getReponse(this.i);
}
}