Hi I would like to access the readonly variable in my Injectable so that the private method handleError can access it. However, it doesn't seem to show.
What I've tried so far but didn't work:
- initialising the readonly variable in the constructor, declaring let this = that in the private method and then trying to access the variable using that.otpErrMismatch
- putting otpService in the provider of my module.ts file
Does anyone know how do I access the readonly otpErrMismatch variable in my handleError method? Appreciate your help thanks!
otp.service.ts
@Injectable({ providedIn: "root" })
export class OtpService {
readonly otpErrMismatch = "otpMismatch"; // this is the variable I want to access
constructor(private http: HttpClient) {}
verify(req): Observable<{}> {
return this.http
.put<{}>(path + "verify", req, {
headers: new HttpHeaders().set(
"Content-Type",
"application/json; charset=utf-8",
),
})
.pipe(
catchError(this.handleError),
);
}
private handleError(error: any) {
console.log(this.otpErrMismatch); // doesn't print out here?
return Observable.throw(this.otpErrMismatch);
}
otp.component.ts
this.otpService
.verify(id,otp)
.subscribe(_ => {
this.router.navigate(["success"]);
},
error => {
console.log(error); // error returns blank
},
);