在Angular2中使用SJCL库 [英] Using SJCL library in Angular2

查看:106
本文介绍了在Angular2中使用SJCL库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想使用具有键入功能的斯坦福Javascript加密库",而且我还会看到

In my app i would like to use "Stanford Javascript Crypto Library" which has a typing and i also see https://github.com/Evgenus/sjcl-typescript-definitions.

我不明白如何在项目中使用它.我如何使用命令 sjcl.encrypt("password", "data")在我的项目中.

I dont understand how i can use it in my project. How can i use the command sjcl.encrypt("password", "data") in my project.

我正在使用角度4,angular-cli beta 2

i am using angular 4, angular-cli beta 2

我已经运行npm install --save-dev @types/sjcl

tsconfig.app.json

tsconfig.app.json

{
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": [ "sjcl" ]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ],
  "extends": "../tsconfig.json"
}

推荐答案

您需要安装 sjcl 软件包:npm install --save sjcl
使用类型(不必要):npm install --save sjcl @types/sjcl

You need to install sjcl package: npm install --save sjcl
With types (not necessary): npm install --save sjcl @types/sjcl

然后在要使用sjcl的代码中添加导入:

Then add import in your code where you want to use sjcl:

import * as sjcl from 'sjcl';

您无需将sjcl添加到tsconfig.app.json文件中.

You don't need to add sjcl into tsconfig.app.json file.

重要!另外,如果您查看类型定义,您会发现它们是为sjcl v1.0.1 编写的,而sjcl的最新版本是 1.0.6 ,因此某些功能可能会出现类型错误.

Important! Also if you look into type definitions you will see they were written for sjcl v1.0.1, last version of sjcl is 1.0.6 so you might get type errors for some functions.

这篇关于在Angular2中使用SJCL库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆