Answer the question
In order to leave comments, you need to log in
Why is the service not visible?
I want to make an eventHandler for the service:
..
import { ToastrService } from 'ngx-toastr';
...
export class AuthService {
constructor(
protected toastr: ToastrService,
protected http: HttpClient
) {
}
signUp(data): Observable<HttpResponse<string>> {
const url = `${this.url}/sign-up`;
return this.http.post<HttpResponse<string>>(url, data, httpOptions).pipe(
catchError(this.handleError)
);
}
protected handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error.message);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
console.error(
`Backend returned code ${error.status}, ` +
`body was: ${error.error}`);
this.toastr.error('Test', 'It\s something testing text');
}
// return an observable with a user-facing error message
return throwError(
'Something bad happened; please try again later.');
}
}
Answer the question
In order to leave comments, you need to log in
catchError(this.handleError)
Your context is lost .
You can do this:
catchError(error => this.handleError(error))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question