I have a small problem and I don't understand why...
The situation : I have a array of all the reservation for the day. I would like, if I click on a button "evening", have only the reservation for the evening.
The getEvening() function is called in parent component when I click on a button.
In my child component.html, I have :
<tbody *ngFor="let resa of resas">
<tr class="addred" (click)='setResa(resa)'>
<td *ngIf="!size">{{ resa.confirmResa }}</td>
<td>{{ resa.arrivee.split(' ')[1] }}</td>
<td>{{ resa.nom_client }}</td>
<td *ngIf="!size">{{ resa.nbre_client }}</td>
<td *ngIf="!size">{{ resa.num_phone_client }}</td>
<td *ngIf="!size">{{ resa.num_table }}</td>
<td *ngIf="!size">{{ resa.formule }}</td>
<td *ngIf="!size" (click)="stopEvent($event)" (mouseover)=setResaId(resa)>
<input class="venu" type="checkbox" clrToggle (change)="came($event)" [checked]="resa.venu === 1" />
</td>
</tr>
</tbody>
In my child component.ts, I have :
export class ReservationTabComponent implements OnInit {
@Input() date: Subject<string>;
@Output() resa = new EventEmitter<any>();
addred: boolean;
resas: any[] = [];
resaId: string;
dateDay: string;
hour: number;
scrHeight: number;
scrWidth: number;
size: boolean;
bool: boolean;
venu: number;
constructor(
private datastore: DatastoreService,
private resaService: ReservationService
) { }
ngOnInit(): void {
this.getScreenSize();
this.date.subscribe((date) => {
this.dateDay = date;
this.setDate(this.dateDay);
});
this.addred = false;
}
setDate(date: string) {
this.datastore.findResaOfTheDay(date)
.subscribe(
(resas) => {
this.resas = resas.data.original;
console.log(this.resas);
});
}
getAll() {
this.setDate(this.dateDay);
}
getMidi() {
this.resas = [];
}
getEvening() {
for (let resa of this.resas) {
this.hour = parseInt(moment().format(resa.arrivee.split(' ')[1]), 10);
if (this.hour > 13) {
this.resas.push(resa); <-- this causing infinite loop...
console.log(resa); <-- this works correctly
}
}
}
}
Actually, when I click on the button, I have a infinte loop with push() method but not with console.log() method...
I don't understand why...