I'm working on a solution where each of the inputs, generated depending on the passenger number, gets additional checkboxes. I want to pass the value of each checkbox and bind it to the input next to it. The plan is to eventually end up with an array in which I have the value of the input field + each checkbox value. I am not sure how to move forward with this. For now, I have:
COMPONENT.HTML:
<li *ngFor="let passenger of createRange(showStorage.passengersNumber); let i=index"><input type="text" [(ngModel)]="passengersData[i]" placeholder="Name and surname">
<input type="checkbox" (click)="addChild($event)">Child
<input type="checkbox" (click)="addLuggage($event)">Luggage
</li>
COMPONENT.TS
constructor() {
this.passengersData = [];
}
public passengersData: any[];
public luggageCounter: number = 0;
public childrenCounter: number = 0;
createRange(number){
var items: number[] = [];
for(var i = 1; i <= number; i++){
items.push(i);
}
return items;
}
addLuggage(event) {
console.log("Added luggage");
this.luggageCounter++
}
addChild(event) {
this.childrenCounter++
console.log(event);
}
Thanks for any help!
STACKBLITZ: https://stackblitz.com/edit/flight-date-picker-with-service-done-qfmn6p