开发者问题收集

Crypt 不是 angular 2 中的构造函数

2016-11-30
1045

I have issue related to cryptography in angular 2, I am using "cryptojs javascript" library javascript library and use SHA512 method for encryption data but is shows "Crypt is not a constructor".

以下是我的代码

在 index.html 中包含 javascript 库

<script type="text/javascript" src="http://cryptojs.altervista.org/api/functions_cryptography.js"></script>

组件文件

import { Component } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AppService } from './app.service';
import { AppSettings } from './app.settings';
import { CartService } from './service/cart.service';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DialogRef, ModalComponent, CloseGuard } from 'angular2-modal';
import { Modal, BSModalContext } from 'angular2-modal/plugins/bootstrap';
import { Overlay, overlayConfigFactory } from 'angular2-modal';
import { MessageModalContext, MessageModal } from './message-modal.component';
declare var Crypt: any;
export class OrderReviewComponent {

 constructor(
    private appService: AppService,
    private router: Router,
    private route: ActivatedRoute,
    public modal: Modal,
    private _cartService: CartService,
) {}

 Order(cartinfo) {
            var Crypt = new Crypt();
            var digest_sha512 = Crypt.HASH.sha512('gtKFFx|4942618|10|[{"name":"abc","description":"abcd","value":"5"},{"name":"xyz","description":"wxyz","value":"2"}]|abc|[email protected]|||||||||||eCwWELxi');
            console.log(digest_sha512.toString());
            this.removecartitem(cartinfo, 2); // status 2 means cancel order click
        }
 }

提前致谢

Vikram

1个回答

您只需要在全局中声明变量

var Crypt = new Crypt();

vicky
2018-05-21