import { Component , OnDestroy } from '@angular/core' ; import { Subscription } from 'rxjs/Subscription' ; import { MessageService } from './_services/index' ; @ Component ( { moduleId : module . id , selector : 'app' , templateUrl : 'app.component.html' } ) export class AppComponent implements OnDestroy { message : any ; subscription : Subscription ; constructor ( private messageService ) { this . subscription = this . messageService . getMessage ( ) . subscribe ( message => { this . message = message ; } ) ; } ngOnDestroy ( ) { this . subscription . unsubscribe ( ) ; } }