sweetalert_1.default不是函数:Angular 5 [英] sweetalert_1.default is not a function : Angular 5
本文介绍了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屋!
查看全文