From 88d216daf6fcbdbe9e917f4580dc20665aa1c00f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 22 Jun 2021 16:02:40 -0400 Subject: [PATCH] LP1929741 cleanup PO subscription; improve charges display Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton Signed-off-by: Jane Sandberg --- .../eg2/src/app/staff/acq/po/charges.component.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.ts index 288c4b1cc9..5f443c1594 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/po/charges.component.ts @@ -1,4 +1,5 @@ -import {Component, OnInit, Input} from '@angular/core'; +import {Component, OnInit, OnDestroy, Input} from '@angular/core'; +import {Subscription} from 'rxjs'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {PcrudService} from '@eg/core/pcrud.service'; @@ -9,10 +10,11 @@ import {PoService} from './po.service'; templateUrl: 'charges.component.html', selector: 'eg-acq-po-charges' }) -export class PoChargesComponent implements OnInit { +export class PoChargesComponent implements OnInit, OnDestroy { showBody = false; autoId = -1; + poSubscription: Subscription; constructor( private idl: IdlService, @@ -23,19 +25,21 @@ export class PoChargesComponent implements OnInit { ngOnInit() { if (this.po()) { // Sometimes our PO is already available at render time. - if (this.po().po_items().length > 0) { - this.showBody = true; - } + this.showBody = this.po().po_items().length > 0; } // Other times we have to wait for it. - this.poService.poRetrieved.subscribe(() => { - if (this.po().po_items().length > 0) { - this.showBody = true; - } + this.poSubscription = this.poService.poRetrieved.subscribe(() => { + this.showBody = this.po().po_items().length > 0; }); } + ngOnDestroy() { + if (this.poSubscription) { + this.poSubscription.unsubscribe(); + } + } + po(): IdlObject { return this.poService.currentPo; } -- 2.11.0