A service has been created to encode passwords using the ts-md5 library in Angular:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Md5 } from 'ts-md5/dist/md5';
@Injectable()
export class HashService {
constructor() { }
generate(str): Observable<string>{
const h = Md5.hashStr(str);
console.log(h, typeof h);
return h;
}
}
The component subscribes to the service like this:
this.hashService.generate(this.form.value.password).subscribe((hash) => {
console.log(hash);
});
An error message is displayed in the console:
ERROR in src/app/shared/services/hash.service.ts(15,5): error TS2322: Type 'string | Int32Array' is not assignable to type 'Observable'. Type 'string' is not assignable to type 'Observable'
Attempts were made to specify a more common type:
generate(str): Observable<any>{
However, the problem persists