我知道以前有人问过这个问题,但我似乎找不到答案,我想询问 sweetalert
在 sweetalert
包含服务中的组件中不起作用用于删除数据。
组件
Swal({
title: 'Are you sure?',
text: 'You will not be able to recover this imaginary file!',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, keep it'
}).then((result) => {
if (result.value) {
this.bookingService.deletedata(data._id).subscribe(data => {
console.log(data);
});
Swal(
'Deleted!',
'Your imaginary file has been deleted.',
'success'
)
} else if (result.dismiss === Swal.DismissReason.cancel) {
Swal(
'Cancelled',
'Your imaginary file is safe :)',
'error'
)
}
})
服务
deletedata(param) {
console.log(param);
let searchUrl = Urlapi + '/pesan/remove' + param;
return this.http.delete(searchUrl, this.jwt()).map(res => res.json());
}
最佳答案
你需要分配 let me = this;在函数开始时。
let me = this;
Swal({
title: 'Are you sure?',
text: 'You will not be able to recover this imaginary file!',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, keep it'
}).then((result) => {
if (result.value) {
me.bookingService.deletedata(data._id).subscribe(data => {
console.log(data);
});
Swal(
'Deleted!',
'Your imaginary file has been deleted.',
'success'
)
} else if (result.dismiss === Swal.DismissReason.cancel) {
Swal(
'Cancelled',
'Your imaginary file is safe :)',
'error'
)
}
})
关于javascript - Sweetalert 中的服务无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51796646/