import { Component , OnInit , Input , ViewEncapsulation } from '@angular/core' ; import { Deal } from '../models/deal' ; import { DealService } from '../service/deal.service' ; import { DateService } from '../../../services/date.service' ; import { Router } from '@angular/router' ; @ Component ( { selector : 'app-deals-by-contact' , encapsulation : ViewEncapsulation . None , templateUrl : './deals-by-contact.component.html' , styleUrls : [ './deals-by-contact.component.css' ] } ) export class DealsByContactComponent implements OnInit { @ Input ( ) contactId : string ; deals : Deal [ ] ; loading : boolean = true ; errorLoading : boolean = false ; constructor ( private dealService , private dateService , private router ) { } ngOnInit ( ) { this . loadDeals ( ) ; } private loadDeals ( ) { this . dealService . fetchDealsByContactId ( this . contactId ) . subscribe ( ( deals ) => this . handleFetchDealsResponse ( deals ) , err => this . handleFetchDealsError ( err ) ) ; } private handleFetchDealsResponse ( deals ) { this . deals = deals ; this . loading = false ; } private handleFetchDealsError ( err ) { this . errorLoading = true ; this . loading = false ; console . error ( err ) ; } editDeal ( dealId ) { let route = '/deals/edit-deal' ; this . router . navigate ( [ route ] , { queryParams : { dealId : dealId } } ) ; } viewDeal ( dealId ) { let route = '/deals/view-deal' ; this . router . navigate ( [ route ] , { queryParams : { dealId : dealId } } ) ; } }