import { Component , OnInit , OnDestroy , ViewEncapsulation } from '@angular/core' ; import { Observable , Subscription } from 'rxjs' ; import { Campaign } from '../../_models/campaign' ; import { CampaignService } from '../../_services/campaign.service' ; @ Component ( { selector : 'campaigns' , templateUrl : 'campaign.component.html' , styleUrls : [ 'campaign.component.css' ] , encapsulation : ViewEncapsulation . None } ) export class CampaignComponent implements OnInit , OnDestroy { campaigns : Observable < Array < Campaign > > ; private subscription : Subscription ; constructor ( private campaignService ) { this . campaigns = campaignService . campaigns ; } ngOnInit ( ) { this . subscription = this . campaigns . subscribe ( campaigns => { } , error => { } ) ; this . campaignService . loadCampaigns ( ) ; } ngOnDestroy ( ) { this . subscription . unsubscribe ( ) ; } loadNew ( ) { this . campaignService . loadCampaigns ( ) ; } }