ORIGINAL EXCEPTION: Encrypt is not defined


#1

I am using Ionic 2 rc3. I am trying to import/include a js file in one of the components.

ts file

// declare var require: any
'use strict';
// var Encrypt = require('pages/service/jsencrypt.min');
declare var Encrypt: any;
...
this.encrypter = new Encrypt.JSEncrypt();

index.html

<script src="pages/service/jsencrypt.min.js"></script>

Before I was using Ionic 2 beta, and it was working perfectly when I didn’t have anything in index.html, and had var Encrypt = require('pages/service/jsencrypt.min'); at the top of the ts file. Since the upgrade to rc3, I cannot seem to get it to import/include the js file.

UPDATE

In the jsencrypt.js file, it has the following code:

var JSEncrypt = function (options) {
    options = options || {};
    this.default_key_size = parseInt(options.default_key_size) || 1024;
    this.default_public_exponent = options.default_public_exponent || '010001'; //65537 default openssl public exponent for rsa key type
    this.log = options.log || false;
    // The private and public key.
    this.key = null;
};

In my ts file, I need to get a handle on JSEncrypt. I used to do the following which worked in the beta:

this.encrypter = new Encrypt.JSEncrypt();

If I try the following:

this.encrypter = this.JSEncrypt();

I get this error in the CLI:

Property 'JSEncrypt' does not exist on type 'PersonService'.

How do I get a handle on JSEncrypt?

Thanks


#2

I’m disappointed that I couldn’t convince you to use JWE.


#3

I do think JWE is better, but I tried it and couldn’t get it to work. Now I have upgraded from beta to rc3, it may be easier. However, I have deadlines and not sure if I have the time to change to JWE. Will see near the end.


#4

Answer: