import { Component , OnInit , OnDestroy } from '@angular/core' ; import { Subscription } from 'rxjs' ; import { AlertService } from '@app/_services' ; @ Component ( { selector : 'alert' , templateUrl : 'alert.component.html' } ) export class AlertComponent implements OnInit , OnDestroy { private subscription : Subscription ; message : any ; constructor ( private alertService ) { } ngOnInit ( ) { this . subscription = this . alertService . getMessage ( ) . subscribe ( message => { this . message = message ; } ) ; } ngOnDestroy ( ) { this . subscription . unsubscribe ( ) ; } }