Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate md5 hash in angular 2 typescript?

Tags:

angular

I am using APi The access to this api is done with hash key that we need to send to the api but we don't really know how to implement.

I found https://www.npmjs.com/package/crypto-js but i dont know how to integrate angular 2

also i found https://www.npmjs.com/package/angular-md5 but i dont know how to import using angular 2 typscript

like image 289
Mohamed Elmi Hassan Avatar asked May 18 '16 12:05

Mohamed Elmi Hassan


2 Answers

For angular 2 use

npm install ts-md5 --save

then import it into component, service or wherever you want

import {Md5} from 'ts-md5/dist/md5';

When you are using systemJS is neccessary set map and package paths.

 map:      {
              'ts-md5': 'src/js/ts-md5',
           },
 packages: {
              'ts-md5': {main: '/md5.js'},                
           }

This is the example from one of my project where I copy neccessary libraries to separate file structure.

like image 71
Jiri HWeb Horalek Avatar answered Nov 19 '22 05:11

Jiri HWeb Horalek


You can get a md5.ts file here:

https://github.com/ManvendraSK/angular2-quickstart/blob/master/app/md5.ts

import it in your component/service:

import {md5} from './md5'; //make sure it points to the folder where the md5.ts file is

then you can use it in your component/service:

let e = md5(this.email);
like image 10
Nik Avatar answered Nov 19 '22 06:11

Nik