Created
March 12, 2019 07:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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