I have two classes in angular and typescript. One class CustomErrorHandlerService is inherting from angular error handler which provides an callback and the other class ErrorProessor is processing that error by using the callback. The problem is that the callback is never getting executed and instead I am getting the following error. I need 2 different classes as I am avoiding some circular dependency errors.
Error: this.handleErrorCallback is not a function
import { Injectable, ErrorHandler } from '@angular/core';
@Injectable()
export class CustomErrorHandlerService implements ErrorHandler{
constructor() {
}
public handleErrorCallback: (error: Error) => void;
handleError(error: Error) {
console.log('Via Custom Error Handler: ' + error.toString());
this.handleErrorCallback(error);
}
}
import { Injectable } from '@angular/core';
import { CustomErrorHandlerService } from './app/custom-error-handler.service';
@Injectable()
export class ErrorProcessor {
constructor(private customErrorHandler: CustomErrorHandlerService) {
this.customErrorHandler.handleErrorCallback = this.handleError;
}
public handleError(): void {
console.log('error processed');
}
}
Thanks.