繁体   English   中英

如何在Ionic2项目whit TypeScript中导入js文件和参考

[英]How to import js file and reference in Ionic2 project whit TypeScript

我尝试在ionic2项目中导入js文件以加密数据,但是运行时出现此错误:

TypeScript error: /app/service/Util.service.ts(49,23): Error TS2663: Cannot find name 'RSAKey'. Did you mean the instance member 'this.RSAKey'?

TypeScript错误:/app/service/Util.service.ts(52,16):错误TS2304:找不到名称“ hex2b64”。

我将库复制到一个文件夹中,并在index.html中引用,这在Angular v1中有效。

我读了ionic2文档,我种了我需要安装npm的种子,购买我不知道该怎么做。 安妮的建议? 谢谢!!:

您可以通过两种方式使用它。

您可以这样做并在脸上拍打打字稿

(<any>window).RSAKey

或者,您可以为您的库编写适当的类型,例如

interface IRSAKey{
  dostuff(): Promise<IRSAKeyResult>;
  hex2b64:string;
}

interface IRSAKeyResult{

}

declare var RSAKey: IRSAKey;

导入界面后,您可以自由使用RSAKey

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM