Sharma Vikram
Sharma Vikram

Reputation: 2470

Crypt is not a constructor in angular 2

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".

Below is my code

Include javascript library in index.html

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

Component File

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
        }
 }

Thanks in advance

Vikram

Upvotes: 0

Views: 1055

Answers (1)

vicky
vicky

Reputation: 46

you only need to declare the veriable in global

var Crypt = new Crypt();

Upvotes: 1

Related Questions