【问题标题】:Using SJCL library in Angular2在 Angular2 中使用 SJCL 库
【发布时间】:2017-03-26 13:59:51
【问题描述】:

在我的应用程序中,我想使用具有打字功能的“Stanford Javascript Crypto Library”,我还看到了https://github.com/Evgenus/sjcl-typescript-definitions

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

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

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

tsconfig.app.json

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

【问题讨论】:

    标签: angular sjcl


    【解决方案1】:

    你需要安装sjcl包:npm install --save sjcl
    带类型(非必需):npm install --save sjcl @types/sjcl

    然后在你想要使用 sjcl 的代码中添加 import:

    import * as sjcl from 'sjcl';
    

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


    重要!此外,如果您查看类型定义,您会发现它们是为 sjcl v1.0.1 编写的,sjcl 的最新版本是 1.0.6 所以你可能会遇到某些函数的类型错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多