我正在使用cryptojs库来加密密码文本并将数据发送到服务器.
但我得到以下错误说,
Error TS2304: Cannot find name 'CryptoJS'.
我按以下方式安装了库:sudo npm install crypto-js
import 'crypto-js/crypto-js';
@Page({
templateUrl: 'build/pages/login/login.html'
})
export class LoginPage {
constructor(private nav: NavController, public http: Http) {
}
validateUser(fieldval, data){
let params = "{'ignoreAuthModule': 'ignoreAuthModule'}";
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append('Parameter', params);
let url = 'app/authentication';
let encrypted_password = Cryptojs.AES.encrypt(fieldval.password, CryptoJS.enc.Base64.parse(data.seed),{mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }).toString().replace(/\+/g, "-").replace(/\//g, '_');
let requestoptions = new RequestOptions({
method: RequestMethod.Post,
url: url,
headers: this.headers,
body: JSON.stringify(data)
})
let body = JSON.stringify(params);
this.http.post(url, body, headers)
.subscribe(
response => {
},
error => {
console.log(error.text());
}
);
}
logError(err) {
console.error('There was an error: ' + err);
}
}
最佳答案 我不知道这个编译错误发生在哪里,但你应该安装crypto-js库的类型:
typings install --ambient crypto-js
有关详细信息,请参阅此问题:
> How to import non-core npm modules in Angular 2 e.g. (to use an encryption library)?