I have a custom error handler service which gets notified whenever there is an error in the application, now i want to notify a component about the error so that the component will show a error dialog to the user, i have tried event emitter, observer but nothing is notifying the component...
here is my service...
@Injectable()
export class ErrorHandlerService implements ErrorHandler {
public apiError: Subject<any> = new BehaviorSubject(false);
apiError$ = this.apiError.asObservable();
constructor(private errorLogService: ErrorLogService
) {}
handleError(error) {
this.apiError.next(error);
console.log("ERROR = " + error);
};}
And the component...
@Component({
selector: 'app-error-log',
templateUrl: './error-log.component.html',
styleUrls: ['./error-log.component.scss'],
providers: [ErrorLogService]
})
export class ErrorLogComponent implements OnInit {
constructor(
private errorHandlerService: ErrorHandlerService
) {
this.errorHandlerService.apiError$.subscribe(data => {
alert("error in component = " + data);
});
}
onNoClick(): void {
// this.dialogRef.close();
}
ngOnInit() {
this.errorHandlerService.apiError$.subscribe(data => {
alert("error in component = " + data);
});
}
}