import { Component , OnInit , Input } from '@angular/core' ; import { Alert , AlertType } from '../_models/index' ; import { AlertService } from '../_services/index' ; @ Component ( { moduleId : module . id , selector : 'alert' , templateUrl : 'alert.component.html' } ) export class AlertComponent { @ Input ( ) id : string ; alerts : Alert [ ] = [ ] ; constructor ( private alertService ) { } ngOnInit ( ) { this . alertService . getAlert ( this . id ) . subscribe ( ( alert ) => { if ( ! alert . message ) { this . alerts = [ ] ; return ; } this . alerts . push ( alert ) ; } ) ; } removeAlert ( alert ) { this . alerts = this . alerts . filter ( x => x !== alert ) ; } cssClass ( alert ) { if ( ! alert ) { return ; } switch ( alert . type ) { case AlertType . Success : return 'alert alert-success' ; case AlertType . Error : return 'alert alert-danger' ; case AlertType . Info : return 'alert alert-info' ; case AlertType . Warning : return 'alert alert-warning' ; } } }