diff --git a/src/app/pages/pages.component.html b/src/app/pages/pages.component.html index 78d8bd1..7057c1a 100644 --- a/src/app/pages/pages.component.html +++ b/src/app/pages/pages.component.html @@ -30,8 +30,7 @@ - + @@ -53,10 +52,10 @@ diff --git a/src/app/pages/pages.component.ts b/src/app/pages/pages.component.ts index 2b80ab1..31b5944 100644 --- a/src/app/pages/pages.component.ts +++ b/src/app/pages/pages.component.ts @@ -1,6 +1,7 @@ import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit, ViewChild } from '@angular/core'; import { MatTable, MatTableDataSource } from '@angular/material/table'; +import { Subscription } from 'rxjs'; import { GatewayService } from '../services/gateway.service'; @Component({ @@ -18,6 +19,7 @@ export class PagesComponent implements OnInit { 'error', 'gateway', ]; + subscriptions: Subscription[] = []; @ViewChild(MatTable, { static: false }) matTable: MatTable; @@ -39,17 +41,27 @@ export class PagesComponent implements OnInit { } cache(type: string, hash: string): void { + + while (this.subscriptions.length) { + const sub = this.subscriptions.pop(); + if (!sub.closed) { + sub.unsubscribe(); + } + } + this.dataSource.data = []; this.matTable.renderRows(); this.gateways.forEach(gateway => { - this.gatewayService.get(gateway, type, hash).subscribe(_ => { - this.dataSource.data.push({ gateway: `${gateway.replace(':type', type).replace(':hash', hash)}`, error: null }); - this.matTable.renderRows(); - }, (error: HttpErrorResponse) => { - this.dataSource.data.push({ gateway: `${gateway.replace(':type', type).replace(':hash', hash)}`, error }); - this.matTable.renderRows(); - }); + this.subscriptions.push( + this.gatewayService.get(gateway, type, hash).subscribe(_ => { + this.dataSource.data.push({ gateway: `${gateway.replace(':type', type).replace(':hash', hash)}`, error: null }); + this.matTable.renderRows(); + }, (error: HttpErrorResponse) => { + this.dataSource.data.push({ gateway: `${gateway.replace(':type', type).replace(':hash', hash)}`, error }); + this.matTable.renderRows(); + }) + ); }); }