File

src/app/stores/error.store.ts

Index

Properties
Methods

Constructor

constructor(router: Router)
Parameters :
Name Type Optional
router Router no

Methods

addError
addError(title: , message: )
Parameters :
Name Optional
title no
message no
Returns : void
displayErrors
displayErrors()
Returns : void
handle
handle(error: IError)
Parameters :
Name Type Optional
error IError no
Returns : void
reset
reset()
Returns : void
showError
showError(title: string, message: string)
Parameters :
Name Type Optional Default value
title string no 'Error'
message string no 'An Error Has Occurred'
Returns : void

Properties

errors
errors:
Default value : new Array<AppError>()
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 ""