打字稿|TypeError:__WEBPACK_IMPORTED_MODULE_1_signature_pad__不是构造函数 [英] Typescript | TypeError: __WEBPACK_IMPORTED_MODULE_1_signature_pad__ is not a constructor
问题描述
我目前正在从事Angular2项目,并且正在尝试使用JS库( https://github.com/szimek/signature_pad )进行签名输入.
I'm currently working on an Angular2 project and I'm trying to use a JS library (https://github.com/szimek/signature_pad) for signature input.
我尝试按原样使用该库,其代码如下:
I've tried using the library as is, with my code as follows:
// .ts file
import * as SignaturePad from 'signature_pad';
export class ... {
private signaturePad: SignaturePad;
ngOnInit() {
let canvas = document.querySelector("canvas");
this.signaturePad = new SignaturePad(canvas);
}
}
.
// .html file
<div...>
<canvas></canvas>
</div>
,启动浏览器页面时出现以下错误:错误错误:未被捕获(承诺):TypeError: WEBPACK_IMPORTED_MODULE_1_signature_pad 不是构造函数
and I get the following error when I launch the browser page: ERROR Error: Uncaught (in promise): TypeError: WEBPACK_IMPORTED_MODULE_1_signature_pad is not a constructor
我也尝试过使用dimpu的angular2-signature-pad,但实际上会出现相同的错误.
I've also tried using dimpu's angular2-signature-pad, but the same error essentially comes up.
推荐答案
假定您具有 signature_pad
的类型( npm install --save-dev @ types/signature_pad
),则必须像下面这样导入和使用它,因为 signature_pad
没有任何导出的成员,而仅将 SignaturePad
类声明到当前作用域中:
Provided you have the typings for signature_pad
(npm install --save-dev @types/signature_pad
), it has to be imported and used like below as signature_pad
does not have any exported members and only declares the class SignaturePad
into the current scope:
import 'signature_pad';
// ...
let canvas = document.querySelector("canvas");
this.signaturePad = new SignaturePad(canvas);
这篇关于打字稿|TypeError:__WEBPACK_IMPORTED_MODULE_1_signature_pad__不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!