In angular, I want to generate a MD5 hash, so I tried installing npm
modules. I tried 'crypto-js', 'angular-md5', but a lot of them with no results.
Finally, I tried with 'ts-md5' and is throwing me an error, as all the others.
First npm install --save ts-md5
and then:
import {Md5} from 'ts-md5/dist/md5';
@Injectable()
export class HeroService {
constructor(
private MD5: Md5
) { }
}
But I get the error:
[Error] ERROR – Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[HeroService -> Md5]:
StaticInjectorError(Platform: core)[HeroService -> Md5]:
NullInjectorError: No provider for Md5!
get
resolveToken
tryResolveToken
[...]
Is there a better module to encrypt in md5? How can I solve this error?
Finally the best way to do it is importing it directly in the component where I have to use it and call it with new Md5()
.
import {Md5} from 'ts-md5/dist/md5';
const md5 = new Md5();
console.log(md5.appendStr('hello').end());
Thanks to all for the quick responses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With