1- import { ChangeDetectorRef , Component , HostListener , OnInit } from '@angular/core' ;
1+ import { ChangeDetectorRef , Component , HostListener , OnDestroy , OnInit } from '@angular/core' ;
22import { firstValueFrom , lastValueFrom } from 'rxjs' ;
33import { TranslateModule } from "@ngx-translate/core" ;
44import { LocalStorageService } from "../../services/local-storage.service" ;
@@ -20,14 +20,16 @@ import {BillingAccountFormComponent} from "../../shared/billing-account-form/bil
2020import { PaymentService } from 'src/app/services/payment.service' ;
2121import { v4 as uuidv4 } from 'uuid' ;
2222import { data } from 'jquery' ;
23+ import { Subject } from 'rxjs' ;
24+ import { takeUntil } from 'rxjs/operators' ;
2325
2426
2527@Component ( {
2628 selector : 'app-checkout' ,
2729 templateUrl : './checkout.component.html' ,
2830 styleUrl : './checkout.component.css'
2931} )
30- export class CheckoutComponent implements OnInit {
32+ export class CheckoutComponent implements OnInit , OnDestroy {
3133 protected readonly faCartShopping = faCartShopping ;
3234 public static BASE_URL : String = environment . BASE_URL ;
3335 PURCHASE_ENABLED : boolean = environment . PURCHASE_ENABLED ;
@@ -52,6 +54,7 @@ export class CheckoutComponent implements OnInit {
5254 providerId :any = null ;
5355 loadingItems :boolean = false ;
5456 orderNote : string = '' ;
57+ private destroy$ = new Subject < void > ( ) ;
5558
5659 constructor (
5760 private localStorage : LocalStorageService ,
@@ -67,7 +70,9 @@ export class CheckoutComponent implements OnInit {
6770 private route : ActivatedRoute ) {
6871 // Bind the method to preserve context
6972 this . orderProduct = this . orderProduct . bind ( this ) ;
70- this . eventMessage . messages$ . subscribe ( async ev => {
73+ this . eventMessage . messages$
74+ . pipe ( takeUntil ( this . destroy$ ) )
75+ . subscribe ( async ev => {
7176 if ( ev . type === 'BillAccChanged' ) {
7277 this . getBilling ( ) ;
7378 }
@@ -363,6 +368,11 @@ export class CheckoutComponent implements OnInit {
363368 }
364369 }
365370
371+ ngOnDestroy ( ) {
372+ this . destroy$ . next ( ) ;
373+ this . destroy$ . complete ( ) ;
374+ }
375+
366376 async initCheckoutData ( ) {
367377 this . providerId = this . route . snapshot . paramMap . get ( 'id' ) ;
368378 let aux = this . localStorage . getObject ( 'login_items' ) as LoginInfo ;
0 commit comments