diff --git a/src/app/meta-campaign/meta-campaign.component.ts b/src/app/meta-campaign/meta-campaign.component.ts index ca95840fe..6878fb116 100644 --- a/src/app/meta-campaign/meta-campaign.component.ts +++ b/src/app/meta-campaign/meta-campaign.component.ts @@ -119,7 +119,7 @@ export class MetaCampaignComponent implements AfterViewChecked, OnDestroy, OnIni ngOnDestroy() { if (isPlatformBrowser(this.platformId) && this.tickerUpdateTimer) { - clearInterval(this.tickerUpdateTimer); + clearTimeout(this.tickerUpdateTimer); } if (this.routeChangeListener) { diff --git a/src/app/my-account/my-account.component.ts b/src/app/my-account/my-account.component.ts index 09b3b9fde..5d09d327b 100644 --- a/src/app/my-account/my-account.component.ts +++ b/src/app/my-account/my-account.component.ts @@ -1,6 +1,6 @@ -import {Component, OnInit} from '@angular/core'; +import { Component, Inject, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core'; import {PageMetaService} from '../page-meta.service'; -import {DatePipe} from '@angular/common'; +import {DatePipe, isPlatformBrowser} from '@angular/common'; import {IdentityService} from "../identity.service"; import {Person} from "../person.model"; import {Router} from "@angular/router"; @@ -17,7 +17,7 @@ import {HttpErrorResponse} from "@angular/common/http"; styleUrls: ['./my-account.component.scss'], providers: [DatePipe] }) -export class MyAccountComponent implements OnInit { +export class MyAccountComponent implements OnDestroy, OnInit { public person: Person; public paymentMethods: PaymentMethod[]|undefined = undefined; @@ -25,11 +25,14 @@ export class MyAccountComponent implements OnInit { registerSucessMessage: string | undefined; protected readonly faExclamationTriangle = faExclamationTriangle; + private savedCardsTimer: undefined | ReturnType; // https://stackoverflow.com/a/56239226 + constructor( private pageMeta: PageMetaService, public dialog: MatDialog, private identityService: IdentityService, private donationService: DonationService, + @Inject(PLATFORM_ID) private platformId: Object, private router: Router, ) { this.identityService = identityService; @@ -48,10 +51,18 @@ export class MyAccountComponent implements OnInit { } else { this.person = person; this.loadPaymentMethods(); + + if (isPlatformBrowser(this.platformId)) { + this.savedCardsTimer = setTimeout(this.checkForPaymentCardsIfNotLoaded, 5_000); + } } }); + } - setTimeout(this.checkForPaymentCardsIfNotLoaded, 5_000); + ngOnDestroy() { + if (isPlatformBrowser(this.platformId) && this.savedCardsTimer) { + clearTimeout(this.savedCardsTimer); + } } loadPaymentMethods() {