deleteDialog(item, func: Function) {
this.dialogService
.open(ConfirmDialogComponent, {
context: {
title:"Are you sure?",
cancelClss: "info",
confirmClss: "danger",
},
})
.onClose.subscribe((confirmed) => {
if (confirmed) func(item);
});
}
The purpose of this function is to open a dialog and execute a specified function if confirmed. The goal is to dynamically pass the function to be executed upon confirmation, allowing for reusability of the dialog functionality in different contexts.
For instance, consider the following sample function:
deleteCurrencyImplementation(cur: Currency) {
this.showSpinner = true;
...
}
While the function is getting executed and receiving the correct object as intended, modifying properties like 'showSpinner' (a public property set to true) within the function can trigger a TypeError in Angular due to it being undefined. To demonstrate how I pass the function within the HTML:
<show-datasource
[tableConfig]="config" [data]="currenciesFromApi"
(deleteEmitter)="deleteDialog($event, deleteCurrencyImplementation)">
</show-datasource>
What could be causing this issue?