简体   繁体   English

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

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

I try to import a js file in my ionic2 project to encript data, but i get this error when i run: 我尝试在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 error: /app/service/Util.service.ts(52,16): Error TS2304: Cannot find name 'hex2b64'. TypeScript错误:/app/service/Util.service.ts(52,16):错误TS2304:找不到名称“ hex2b64”。

I copy the library in a folder and i reference in index.html, this works in Angular v1. 我将库复制到一个文件夹中,并在index.html中引用,这在Angular v1中有效。

I read in the ionic2 documentation and i seed that i need to instal whit npm, buy i dont know how do this. 我读了ionic2文档,我种了我需要安装npm的种子,购买我不知道该怎么做。 Anny sugestion?? 安妮的建议? Thanks!!: 谢谢!!:

There are two ways you can work with this. 您可以通过两种方式使用它。

One you can hack it and slap typescript in the face by doing this 您可以这样做并在脸上拍打打字稿

(<any>window).RSAKey

Or you can write a proper typing for your library something like this 或者,您可以为您的库编写适当的类型,例如

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

interface IRSAKeyResult{

}

declare var RSAKey: IRSAKey;

After this import your interface and you can use RSAKey freely 导入界面后,您可以自由使用RSAKey

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

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