2

I'm pretty new to Angular. I'm trying to incorporate the openPGP library to my app (client side). I need some help on how to incorporate a javascript library to the Angular App. Thanks!

I'm reading through the openPGP docs https://github.com/openpgpjs/openpgpjs and the example provide in the docs is below:

var openpgp = require('openpgp');
var key = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----';
var publicKey = openpgp.key.readArmored(key);
var pgpMessage = openpgp.encryptMessage(publicKey.keys, 'Hello, World!');

I prefer not to use require to source in openPGP to my app. So I've tried var openpgp = window.openpgp; which seems to not throw any error here. However, I get TypeError: Cannot read property 'key' of undefined error.

I should mention that I have installed openpgp using bower install.

I'm still trying to figure out what I can do to refer to openPGP in the Angular app. Thanks.

4

1 回答 1

2

如果您在客户端,请使用脚本标签,例如

<script src="/path/to/openpgp.js"></script>

代替require()

于 2016-04-18T03:40:03.563 回答