我知道之前曾有人问过这个问题,但我似乎找不到答案,我想问一下sweetalert
的include服务中删除数据的组件中sweetalert
不能正常工作。 / p>
组件
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());
}
答案 0 :(得分:1)
您需要分配让我=这个;在功能开始时。
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'
)
}
})