1

I have variable with base64 encoded string and I would like to decode it and after that, displayed it in a HTML template. I am using Angular 2 with typescript.

So I am looking for some base64 encode/decode library for Angular2/Typescript and some options to create an image from decoded string.

Thanks

Loutocký
  • 822
  • 2
  • 15
  • 28
  • 1
    So sorry, I mixed it up with Dart because I was working on Dart questions previously. – Günter Zöchbauer Apr 15 '16 at 11:44
  • to `encode/decode` in base64 javascript's `btoa()/atob()` methods would be enough, to generate a QR code `angular` had [this](https://github.com/monospaced/angular-qrcode) third party component but [support for `angular2` still seems under consideration](https://github.com/monospaced/angular-qrcode/issues/39) – Ankit Singh Apr 15 '16 at 11:56

1 Answers1

2

I solved it with something like this:

this.QRCode = "data:image/png;base64," + base64EncodedQRCodeInString;

this.QRCode is mapped to template by property binding, for example <img [src]="QRCode" />, it is not neccessary to decode it from base64. The browsers have the full support for base64 encoded strings.

Loutocký
  • 822
  • 2
  • 15
  • 28
  • How are you creating your base64EncodedQRCodeInString ? And what is "this" in your code here ? – kris Jun 17 '16 at 03:23
  • base64EncodedQRCodeInString is from JAVA backend REST API, it was created by: ByteArrayOutputStream stream = null; stream = QRCode .from(generatedQRInput + delimeter + signWithKeyId.getId() + ";" + Base64Utils.encodeToString(signWithKeyId.getSign())) .withCharset("UTF-8") .stream(); if (stream != null) { return Base64Utils.encodeToString(stream.toByteArray()); } – Loutocký Jun 22 '16 at 08:54