问题
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.
I dont understand how i can use it in my project. How can i use the command
sjcl.encrypt("password", "data")
in my project.
i am using angular 4, angular-cli beta 2
i have run 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"
}
回答1:
You need to install sjcl package: npm install --save sjcl
With types (not necessary): npm install --save sjcl @types/sjcl
Then add import in your code where you want to use sjcl:
import * as sjcl from 'sjcl';
You don't need to add sjcl
into tsconfig.app.json file.
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.
来源:https://stackoverflow.com/questions/43029690/using-sjcl-library-in-angular2