After incorporating a custom confirm dialog into a function, I noticed that the reference to "this" became undefined in all parts of the code except for within the dialog function.
The function looks like this:
onDelete(CTId) {
this.confirmDialogService.confirmThis(
"Confirm Delete",
() => {
this.service.deleteContactDetail(CTId).subscribe(
res => {
this.service.refreshList();
this.toastr.warning("Deleted Successfully", "Contact Details");
},
err => {
console.log(err);
this.toastr.error("Failed to Delete");
}
);
},
() => {
console.log("closed dialog");
}
);
}
In the definition for the confirmDialogService, "this" is set as this: this
, while elsewhere it's defined as any
.