sweetalert_1.default 不是函数:Angular 5 [英] sweetalert_1.default is not a function : Angular 5

查看:21
本文介绍了sweetalert_1.default 不是函数:Angular 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在官方 链接 中发现 SweetAlert,所以我想在我的应用 angular5.

I'm about discovering SweetAlert in the official link , so i wanted to use it in my app angular5 .

我是这样安装的:

npm install sweetalert --save

我已将其导入到我的组件中:edit-client.component 与此:

I have imported it in my component : edit-client.component with this :

  import swal from 'sweetalert';

这是我尝试使用的文件 editClient.component.ts :

Here is the file editClient.component.ts where i tried to use it :

import swal from 'sweetalert';

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

EditClient(){
    this.clientService.updateClient(this.client)
      .subscribe(data=>{
        console.log(data);

        swal('mise a jour effecture !');

        this.router.navigate([ '../../../list' ], { relativeTo: this.activatedRoute });
        },err=>{
        console.log(err);
        alert("Probleme");
      })
  }


}

但是在运行这个例子时,我看不到警报,而是收到一个错误:

But while running this exemple , i can't see the alert and i get an error instead :

RROR TypeError: sweetalert_1.default is not a function
    at SafeSubscriber.eval [as _next] (edit-clients.component.ts:39)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:240)
    at SafeSubscriber.next (Subscriber.js:187)
    at Subscriber._next (Subscriber.js:128)
    at Subscriber.next (Subscriber.js:92)

我做错了什么?

推荐答案

对于那些遇到同样问题的人,我改为:

For those who faced the same problem i imported instead :

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

然后使用:

swal('hello world'); 

这解决了问题.

这篇关于sweetalert_1.default 不是函数:Angular 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆