Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SweetAlert删除angular5中的错误_Angular_Angular5_Frontend_Sweetalert - Fatal编程技术网

SweetAlert删除angular5中的错误

SweetAlert删除angular5中的错误,angular,angular5,frontend,sweetalert,Angular,Angular5,Frontend,Sweetalert,使用angular5时,我试图在代码中使用SweetAlert for delet选项,但出现了一些错误: 我使用的功能与官方的相同 这是.ts中的代码 import * as _swal from 'sweetalert'; import { SweetAlert } from 'sweetalert/typings/core'; const swal: SweetAlert = _swal as any; @Component({ selector: 'app-clients',

使用angular5时,我试图在代码中使用SweetAlert for delet选项,但出现了一些错误:

我使用的功能与官方的相同

这是.ts中的代码

import * as _swal from 'sweetalert';
import { SweetAlert } from 'sweetalert/typings/core';
const swal: SweetAlert = _swal as any;

@Component({
  selector: 'app-clients',
  templateUrl: './clients.component.html',
  styleUrls: ['./clients.component.scss']
})
export class ClientsComponent implements OnInit {

  pageClients:any;

   ngOnInit() {
    this.doSearch();
    this.getAllClientsList();
  }

  delete(p:Clients){

    swal({
          title: "Are you sure?",
          text: "Once deleted, you will not be able to recover this imaginary file!",
          icon: "warning",
          buttons: true,
          dangerMode: true,
        })
          .then((willDelete) => {
            if (willDelete) {
                  this.clientService.deleteClient(p.id)
                  .subscribe(data=>{
                  this.pageClients.content.splice(
                  this.pageClients.content.indexOf(p),1
                     );
                  },err=>{
                  console.log(err);
                   })
              swal("Poof! Your imaginary file has been deleted!", {
                icon: "success",
              });
            } else {
              swal("Your imaginary file is safe!");
            }
          });
    }
}
如何解决这个问题

编辑

delete(p:Clients){

    swal({
      title: "are you sur ?",
      text: " nce deleted, you will not be able to recover this imaginary file!!",
      type: 'warning',
      showConfirmButton: true,
      showCancelButton: true
    })
      .then((willDelete) => {

        if (willDelete) {

          this.clientService.deleteClient(p.id)
            .subscribe(data=>{
              this.pageClients.content.splice(
                this.pageClients.content.indexOf(p),1
              );
            },err=>{
              console.log(err);
            })

          swal({
           title: " great",
            type: 'success',
          });
        } else {
          swal("you have not deleted this client yet ");
        }
      });
  }
当出现此警报时,无论何时选择“确定”或“取消”,我都会收到“很棒”警报


当我试着打印它时,我知道它总是执行第一个if(willDelete),因此,无论我选择“确定”还是“取消”,此客户端都将被删除。

当您尝试使用
swal
功能时,您需要仅提供
SweetAlertOptions
界面上可用的属性。它有许多属性,但这些属性不存在

icon: "warning",
 buttons: true,
 dangerMode: true,
相反,您可以使用:

type :'warning',
showConfirmButton: true,
showCancelButton: true,
最终代码

swal({
  title: "Are you sure?",
  text: "Once deleted, you will not be able to recover this imaginary file!",
  type: 'warning',
  showConfirmButton: true,
  showCancelButton: true     
})
.then((willDelete) => {
  if (willDelete) {
        this.clientService.deleteClient(p.id)
        .subscribe(data=>{
        this.pageClients.content.splice(
        this.pageClients.content.indexOf(p),1
           );
        },err=>{
        console.log(err);
         })
    swal({title:"Poof! Your imaginary file has been deleted!",
      type: "success",
    });
  } else {
    swal("Your imaginary file is safe!");
  }
});
可以肯定的是

我正在使用下面的src

npm install --save sweetalert2 @toverux/ngx-sweetalert2