Reputation: 309
I am getting "Cannot invoke an expression whose type lacks a call signature. Type 'typeof import("sweetalert2")' has no compatible call signatures." this error while using SWAL in angular.
"ng2-sweetalert2": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/ng2-sweetalert2/-/ng2-sweetalert2-0.0.8.tgz",
"integrity": "sha1-+VkDV2dqeLIMf3eFTLVt/cJda0Q=",
"requires": {
"lodash.assign": "^4.0.8",
"sweetalert2": "^5.2.0"
},
"dependencies": {
"es6-promise": {
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.6.tgz",
"integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q=="
},
"sweetalert2": {
"version": "5.3.8",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-5.3.8.tgz",
"integrity": "sha1-YALBhFPQYMQLnMVL+DoBDHHjlik=",
"requires": {
"es6-promise": "^4.2.6"
}
}
}
}
"sweetalert2": {
"version": "8.9.0",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-8.9.0.tgz",
"integrity": "sha512-gI+wL44QRbfd6FvRVB8KKLQPhD/8jP3XUNrvYGcSlU7IA09dQtQw3rrLCbM3c+HY0L3O8VTz1Gvu29n8ryIgag=="
}
"dependencies":{
"ng2-sweetalert2": "0.0.8",
"sweetalert2": "^8.9.0",}
In a component my code is like below
import * as swal from 'sweetalert2';
swal({
text: 'Login Successful!',
timer: 1000,
onOpen: () => {
swal.showLoading()
}
})then((result) => {
if (result.dismiss === swal.DismissReason.timer) {
// calling few required functions here
}
})
In the component I am getting the above mentioned error. Searched a lot but couldn't figure out the problem. please help me.
Upvotes: 2
Views: 4267
Reputation: 716
I also had the same issue.Use
swal.fire()
instead of
swal()
It will solve your problem.
Upvotes: 5
Reputation: 1177
You installed two dependencies via package.json:
sweetalert2
, which is a pure(!) javascript library. It has nothing to do with angular.ng2-sweetalert2
, which is an Angular service, which wraps the native sweetalert2
library into an Angular service. According to the GitHub page, this is deprecated. I recommend removing sweetalert2
and from your package.json, and add ngx-sweetalert2:
npm install --save sweetalert2 @sweetalert2/ngx-sweetalert2
Set up the module described in ngx-sweetalert2, from there, you have multiple ways to make it work, via directive or component.
Upvotes: 1