import { Component, OnInit, ViewChild, Input, OnDestroy } from '@angular/core'; import { Subscription } from 'rxjs'; import { MatDialog, MatDialogRef } from '@angular/material'; import { Router } from '@angular/router'; import { HBORModalService } from '../../services/hbor-modal.service'; import { ModalSubject } from '../../interfaces/modal.subject'; @Component({ selector: 'hbor-error', templateUrl: './error.component.html', styleUrls: ['./error.component.css'] }) export class ErrorComponent implements OnInit, OnDestroy { @Input() width = '30%' show = false; title: string; description: string; aditionalInfo: string; private subscription: Subscription; constructor(private modalService: HBORModalService, public dialog: MatDialog, private router: Router) { } ngOnInit() { this.subscription = this.modalService.modalState$ .subscribe((state: ModalSubject) => { this.show = state.showError; this.title = state.title; this.description = state.description; if (state.aditionalInfo != null || state.aditionalInfo !== '') { this.aditionalInfo = state.aditionalInfo; } if (this.show) { this.openDialog(this.title, this.description, this.aditionalInfo); } }); } ngOnDestroy() { this.subscription.unsubscribe(); } openDialog(title?: string, description?: string, aditionalInfo?: string, reload?: boolean, logOut?: boolean) { const dialogRef = this.dialog.open(ErrorDialogComponent, { disableClose: true }); dialogRef.componentInstance.title = title; dialogRef.componentInstance.description = description; dialogRef.componentInstance.aditionalInfo = aditionalInfo; dialogRef.afterClosed().subscribe(result => { this.modalService.isOpen = false; description = result; }); } } @Component({ selector: 'hbor-error-dialog', templateUrl: 'error-dialog.html', styleUrls: ['./error.component.css'] }) export class ErrorDialogComponent { @Input() title: string; @Input() description: string; @Input() aditionalInfo: string; panelOpenState = false; constructor(public dialogRef: MatDialogRef) { } }