src/app/stores/error.store.ts
Properties |
content |
content:
|
Type : any
|
Defined in src/app/stores/error.store.ts:7
|
title |
title:
|
Type : string
|
Defined in src/app/stores/error.store.ts:6
|
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { AppError } from '../models';
interface IError {
title: string;
content: any;
}
@Injectable()
export class ErrorStore {
errors = new Array<AppError>();
constructor(private router: Router) {}
handle(error: IError) {
this.addError(error.title, error.content);
this.displayErrors();
}
reset() {
this.errors = new Array<AppError>();
}
addError(title, message) {
const error = new AppError(title, message);
this.errors.push(error);
}
showError(title = 'Error', message = 'An Error Has Occurred') {
const error = new AppError(title, message);
this.errors.push(error);
this.router.navigate(['/error']);
}
displayErrors() {
this.router.navigate(['/error']);
}
}