地穴不是角2中的构造函数

时间:2016-11-30 06:44:25

标签: javascript angular

  

我在角度2中遇到与加密相关的问题,我正在使用" cryptojs javascript"库javascript library并使用SHA512方法进行加密数据,但是显示" Crypt不是构造函数"。

以下是我的代码

在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|vikram.sharma@xymob.in|||||||||||eCwWELxi');
            console.log(digest_sha512.toString());
            this.removecartitem(cartinfo, 2); // status 2 means cancel order click
        }
 }

提前致谢

维克拉姆

1 个答案:

答案 0 :(得分:1)

您只需在全局

中声明可验证的内容
  

var Crypt = new Crypt();