How to encode or decode a string in angular 2 with base64 ??? My front-end tool is Angular 2. I had a password string, before passing it to API I need to base64 encode. Since in service base64 encoded string will be decoded.
So I am looking for some base64 encode/decode library for Angular2/Typescript and some options.
Thanks!!!
Use
btoa()
for encode andatob()
for decodeEncoded Text:
console.log(btoa(this.text_val)); //eW91ciBlbmNvZGluZyB0ZXh0
Decoded Text:
console.log(atob("eW91ciBlbmNvZGluZyB0ZXh0")); //your encoding text
For encoding to base64 in Angular2, you can use btoa() function.
Example:-
For deconding from base64 in Angular2, you can use atob() function.
Example:-
Use the
btoa()
function to encode:To decode, you can use the
atob()
function:Use
btoa("yourstring")
more info: https://developer.mozilla.org/en/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
TypeScript is a superset of Javascript, it can use existing Javascript libraries and web APIs