I'm facing an issue with deleting an item in my Angular CLI app using Sweet Alert as a confirmation dialog. The code snippet below is written in TypeScript:
import { AuthenticationService } from '../../../services/authentication.service';
declare var swal: any;
export class AdminUsersComponent implements OnInit {
constructor(
private authService: AuthenticationService,
) { }
deleteUser(id) {
let userData = {
user_id: id
};
swal({
title: "Are you sure?",
text: "You will not be able to recover this!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}, function(){
this.authService.deleteUser(userData).subscribe(data => {
// response
});
});
}
}
After confirming the delete action, I encountered an error stating that "this.authserivce" is undefined. The functionality works fine without using Sweet Alert for confirmation. I suspect I need to pass a parameter in the callback function but unsure what it should be. Any insights on how to resolve this issue?