Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created March 12, 2019 07:52
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { BehaviorSubject, Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ErrorService {
private errorSource = new BehaviorSubject<Error | HttpErrorResponse>(null);
public _error$: Observable<Error | HttpErrorResponse> = this.errorSource.asObservable();
set error(error: Error | HttpErrorResponse) {
this.errorSource.next(error);
}
constructor(public router: Router) { }
clearErrors() {
this.error = null;
this.router.navigate(['/home']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment