File

src/app/providers/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
Default value : new Array<AppError>()
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { AppError } from '../../models/error.model';

interface IError {
  title: string;
  content: any;
}
@Injectable()
export class ErrorStore {
  errors = new Array<AppError>();

  constructor(private router: Router) {}

  handle(error: IError) {
    this.showError(error.title, error.content);
  }

  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 ""