import { Input, Component } from '@angular/core'; @Component({ selector: 'ngbd-alert-closeable', templateUrl: './alert-closeable.html' }) export class NgbdAlertCloseable { @Input() public alerts: Array = []; private backup: Array; constructor() { this.alerts.push({ id: 1, type: 'success', message: 'This is an success alert', }, { id: 2, type: 'info', message: 'This is an info alert', }, { id: 3, type: 'warning', message: 'This is a warning alert', }, { id: 4, type: 'danger', message: 'This is a danger alert', }, { id: 5, type: 'primary', message: 'This is a primary alert', }, { id: 6, type: 'secondary', message: 'This is a secondary alert', }, { id: 7, type: 'light', message: 'This is a light alert', }, { id: 8, type: 'dark', message: 'This is a dark alert', }); this.backup = this.alerts.map((alert: IAlert) => Object.assign({}, alert)); } public closeAlert(alert: IAlert) { const index: number = this.alerts.indexOf(alert); this.alerts.splice(index, 1); } public reset() { this.alerts = this.backup.map((alert: IAlert) => Object.assign({}, alert)); } } export interface IAlert { id: number; type: string; message: string; }