服务在Sweetalert中不起作用

时间:2018-08-11 05:07:31

标签: javascript jquery angular typescript

我知道之前曾有人问过这个问题,但我似乎找不到答案,我想问一下sweetalert的include服务中删除数据的组件中sweetalert不能正常工作。 / p>

enter image description here

组件

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());
    }

1 个答案:

答案 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'
        )
    }
})
相关问题