I have a click handler on an angular HTML template that passes the $event argument to the handler function. I need to call this function on ngOnInit programmatically to essentially bootstrap my component with default data as if the user had clicked the button:
Here is the template reference:
<button *ngIf="options?.addRow"
mat-button
(click)="addRow($event)">
<span>Add Row</span>
</button>
Here is the addRow method:
addRow(event: any) {
const currentData = cloneDeep(this.formArrayValues);
currentData.push(this.emptyRowFromColumnDef); // Append new row to END of table
this.updateTableData(currentData);
if (this.paginationEnable && this.paginator) {
timer().subscribe(() => this.paginator.lastPage());
}
timer(1).subscribe(() => this.changeDetectorRef.markForCheck());
event.preventDefault(); // EVENT arg is needed here
}
And here is where I need to programmatically call addRow in ngOnInit() but I need to pass the event as if it were a manual click:
ngOnInit() {
event: ? // how to define the $event to pass to addRow?
this.addRow(this.event);
}