-import {Component, OnInit, AfterViewInit, ViewChild, ViewChildren, QueryList} from '@angular/core';
+import {Component, OnInit, AfterViewInit, ViewChild, ViewChildren, QueryList, OnDestroy} from '@angular/core';
import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
-import {Router, ActivatedRoute, ParamMap, NavigationEnd} from '@angular/router';
+import {Router, ActivatedRoute, ParamMap, RouterEvent, NavigationEnd} from '@angular/router';
+import {filter, takeUntil} from 'rxjs/operators';
+import {Subject} from 'rxjs';
import {StaffCommonModule} from '@eg/staff/common.module';
import {IdlService, IdlObject} from '@eg/core/idl.service';
import {PcrudService} from '@eg/core/pcrud.service';
templateUrl: './acq-search.component.html'
})
-export class AcqSearchComponent implements OnInit, AfterViewInit {
+export class AcqSearchComponent implements OnInit, AfterViewInit, OnDestroy {
searchType = '';
validSearchTypes = ['lineitems', 'purchaseorders', 'invoices', 'selectionlists'];
@ViewChildren(PicklistResultsComponent) plResults: QueryList<PurchaseOrderResultsComponent>;
previousUrl: string = null;
+ public destroyed = new Subject<any>();
constructor(
private router: Router,
this.ngOnInit(); // TODO: probably overkill
});
});
- this.router.events.subscribe(routeEvent => {
+ this.router.events.pipe(
+ filter((event: RouterEvent) => event instanceof NavigationEnd),
+ takeUntil(this.destroyed)
+ ).subscribe(routeEvent => {
if (routeEvent instanceof NavigationEnd) {
// force reset of grid data source if we're navigating from
// a search tab to the same search tab
ngAfterViewInit() {}
+ ngOnDestroy(): void {
+ this.destroyed.next();
+ this.destroyed.complete();
+ }
+
}