问题
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