File

src/app/stores/error.store.ts

Index

Properties

Properties

content
content: any
Type : any
title
title: string
Type : string
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']);
  }
}

results matching ""

    No results matching ""