import { Component , OnInit , OnDestroy } from '@angular/core' ; import { Customer } from '../shared/interfaces' ; import { DataService } from '../core/services/data.service' ; import { SubSink } from 'subsink' ; @ Component ( { selector : 'app-communication' , templateUrl : './communication.component.html' } ) export class CommunicationComponent implements OnInit , OnDestroy { customers : Customer [ ] = [ ] ; customer : Customer ; private subs = new SubSink ( ) ; constructor ( private dataService ) { } ngOnInit ( ) { this . subs . sink = this . dataService . getCustomers ( ) . subscribe ( ( custs ) => this . customers = custs ) ; } selected ( cust ) { this . customer = cust ; } addCustomerPush ( ) { this . dataService . addCustomer ( ) . subscribe ( ( custs ) => this . customers = custs ) ; } addCustomerClone ( ) { this . dataService . addCustomerClone ( ) . subscribe ( ( custs ) => this . customers = custs ) ; } ngOnDestroy ( ) { this . subs . unsubscribe ( ) ; } }