I am trying to import OpenPgp to an Ionic 2 app that is wrote in Angular 2 and TypeScript.
However, TypeScript is importing the Types as the module instead of the module. OpenPgp is wrote with AMD, ES6 module support, all the things I have tried are not working.
Aside from Encryption in JS, how do I make this work?
You can just add the script as javascript. I know that ionic does not use angular-cli yet but they should have a way to add scripts. For with angular-cli project you can do:
add lib to angular-cli.json
"scripts": [
.....
"../node_modules/openpgp/dist/openpgp.js"
],
add a dummy declaration to keep TS happy:
declare var openpgp: any;
This comment has the answer, need to add the openpgp library in the index.html instead https://stackoverflow.com/a/41372258/1161746
<script src="assets/scripts/openpgp.min.js"></script>
<script>
window.openpgp.initWorker({ path:'/assets/scripts/openpgp.worker.min.js' });
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.