import { Component, OnInit, OnDestroy } from '@angular/core'; @Component({ selector: 'app-feedback-panel', templateUrl: './feedback-panel.component.html', styleUrls: ['./feedback-panel.component.css'] }) export class FeedbackPanelComponent implements OnInit, OnDestroy { Header: string; Body: string; Details: string; Class: string; timeout: any; constructor() { } ngOnInit() { } ngOnDestroy() { this.timeout } triggerSuccess(body: string, autohide: boolean = true) { this.Details = null; this.Class = "alert-success"; this.Header = "Success!"; this._triggerWithText(body, autohide); } triggerError(error) { this.Class = "alert-danger"; this.Details = null; let errorMessage; console.log(error); try { if (error.error && error.error.message) { errorMessage = error.error.message; } else if (error.message) { errorMessage = error.message; } else { errorMessage = "Sorry, something went wrong"; } } catch (err) { errorMessage = err; if (error._body != null) { this.Details = error._body; } } this.Header = "An Error Occurred"; this._triggerWithText(errorMessage); } private _triggerWithText(text: string, autohide: boolean = false) { this.Body = text; if (autohide) { this.timeout = setTimeout(() => { this.reset(); }, 3000); } } reset() { return new Promise((resolve) => { this.Header = null; this.Body = null; this.Class = null; return resolve(); }) } }