I have this function delete function
delete(data:any) {
Swal.fire({
title: 'Are you sure?',
text: 'You want to delete!',
showCancelButton: true,
confirmButtonText: 'Yes, Delete it!',
cancelButtonText: 'No, keep it'
}).then(async (result) => {
if (result.isConfirmed) {
this.Delete(data);
this.getList();
}
})
}
I want to update the list after delete but getList
is called before Delete
i was using promise
await this.Delete(data).toPromise();
but getting this error
Property 'toPromise' does not exist on type 'void'
Delete function
Delete(data) {
this.param = {.....
}
this.Service.delete(this.param).subscribe(res => {
this.toastr.success('deleted successfully');
})
}
Any solution Thanks
CodePudding user response:
Your Delete function must return an Observable or Promise:
Delete(data) {
...
return this.Service.delete(this.param).toPromise();
}
and you can do this:
...
await this.Delete(data);
or
Delete(data) {
...
return this.Service.delete(this.param);
}
and you can do this:
...
await this.Delete(data).toPromise();
CodePudding user response:
if (result.isConfirmed) {
return this.Delete(data).then(async () => {
await this.getList()
});
}