using SweetAlert library in TypeScript -
i have used sweetalert in typescript getting error message:
uncaught typeerror: sweet.default not function
i installed sweetalert via npm sweetalert --save
, via types command npm --save @types\sweetalert
code app.ts:
import * $ "jquery" import * swal 'sweetalert'; export class med { public showalert() { $("#med").click(function() { swal({ title: 'are sure?', text: "you won't able revert this!", type: 'warning', }) }) } //end showalert } //end class let f = new med() f.showalert();
code config.ts:
require( ['app'], function(app: any) { }, function(err: any) { console.error('error: ', err.requiretype); console.error('modules: ', err.requiremodules); } );
code tsconfig.json:
{ "compileroptions": { "target": "es5", /* specify ecmascript target version: 'es3' (default), 'es5', 'es2015', 'es2016', 'es2017', or 'esnext'. */ "module": "amd", /* specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'esnext'. */ "noimplicitany": true, "strictnullchecks": true, "outdir": "./build", "lib": ["es2016", "dom"], /* redirect output structure directory. */ "strict": true /* enable strict type-checking options. */ }, "files": [ "sweet.d.ts" ], "exclude": [ "./build", "./node_modules", "sweet.d.ts" ] }
code index.html:
<!doctype html> <html> <head> <title>test ts</title> <link rel="stylesheet" href="build/sweetalert.css"> <script data-main="build/config.js" src="node_modules/requirejs/require.js"></script> </head> <body> <button id="med">affiche</button> <div id="test" style="background-color: #eee;color:#444;font-size: 28px;padding: 25px;display: none;"> bonjour</div> </body> </html>
please me solve issue.
Comments
Post a Comment