Essentially, I am working with an array of objects and my goal is to pass the index of a selected object from the array to another component using @Input
.
The issue arises when I try to select the same item twice because the ngOnChanges
function does not recognize it as a change when the value remains the same (e.g., going from 1 to 1). As a result, I am unable to select the same object consecutively.
Child Component:
@Input('editAppointmentIndex') editAppointmentIndex: number;
ngOnChanges(changes: SimpleChanges) {
console.log(changes);
if (changes.editAppointmentIndex && changes.editAppointmentIndex.currentValue != undefined) {
// Perform actions on the selected object
}
}
Parent Component:
<child-component [editAppointmentIndex]="currentAppointmentIndex"></child-component>
currentAppointmentIndex: number;
onEdit(i) {
this.currentAppointmentIndex = i;
}
Sibling Component:
<button class="edit" (click)="onEdit(i)">Edit</button>
@Output() onEdit_: EventEmitter<number> = new EventEmitter<number>();
onEdit(i) {
this.onEdit_.emit(i);
}