sweetalert_1.default is not a function : Angular 5

那年仲夏 提交于 2020-06-17 00:50:33

问题


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

i have installed it this way :

npm install sweetalert --save

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

  import swal from 'sweetalert';

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)

What i'm doing wrong ?


回答1:


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;

And used then :

swal('hello world'); 

this fixed the issue.



来源:https://stackoverflow.com/questions/50799359/sweetalert-1-default-is-not-a-function-angular-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!