alert.component.ts 921B

1234567891011121314151617181920212223242526272829303132333435
  1. import { Component, OnDestroy, OnInit } from '@angular/core';
  2. import { JhiAlertService } from 'ng-jhipster';
  3. @Component({
  4. selector: 'jhi-alert',
  5. template: `
  6. <div class="alerts" role="alert">
  7. <div *ngFor="let alert of alerts" [ngClass]="setClasses(alert)">
  8. <ngb-alert *ngIf="alert && alert.type && alert.msg" [type]="alert.type" (close)="alert.close(alerts)">
  9. <pre [innerHTML]="alert.msg"></pre>
  10. </ngb-alert>
  11. </div>
  12. </div>`
  13. })
  14. export class JhiAlertComponent implements OnInit, OnDestroy {
  15. alerts: any[];
  16. constructor(private alertService: JhiAlertService) {}
  17. ngOnInit() {
  18. this.alerts = this.alertService.get();
  19. }
  20. setClasses(alert) {
  21. return {
  22. toast: !!alert.toast,
  23. [alert.position]: true
  24. };
  25. }
  26. ngOnDestroy() {
  27. this.alerts = [];
  28. }
  29. }