import { Component } from '@angular/core' ; import { NavigationStart , Router } from '@angular/router' ; import { ErrorService , ErrorValue } from '../../providers/errorhandler.service' ; @ Component ( { templateUrl : './errorhandler.component.html' , selector : 'tw-error' , styleUrls : [ './errorhandler.component.scss' ] } ) export class ErrorComponent { displayError = false ; error : string ; reason = null ; constructor ( private router , private errorService ) { this . errorService . onError$ . subscribe ( ( errorValue ) => { if ( errorValue . error ) { this . error = errorValue . error ; this . reason = errorValue . reason ; this . displayError = true ; } else { this . displayError = false ; this . error = '' ; this . reason = null ; } } ) ; this . router . events . subscribe ( ( event ) => { if ( event instanceof NavigationStart ) { this . displayError = false ; this . error = '' ; this . reason = null ; } } ) ; } retry ( ) { this . displayError = false ; this . error = '' ; } }