From 5bcde6bae25263a6014469eab6440c2239df434f Mon Sep 17 00:00:00 2001 From: Marcelo Puebla Date: Fri, 31 Jan 2020 12:47:20 -0300 Subject: [PATCH] Fix Desuscribo cuando se destruye compoenentes --- src/app/modules/pago-electronico/pago-electronico.component.ts | 5 ++++- src/app/modules/pago-tarjeta/pago-tarjeta.component.ts | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/modules/pago-electronico/pago-electronico.component.ts b/src/app/modules/pago-electronico/pago-electronico.component.ts index d681010..819864b 100644 --- a/src/app/modules/pago-electronico/pago-electronico.component.ts +++ b/src/app/modules/pago-electronico/pago-electronico.component.ts @@ -4,6 +4,7 @@ import { Router } from '@angular/router'; import { APP_SETTINGS } from 'src/etc/AppSettings'; import { BsModalService } from 'ngx-bootstrap/modal'; import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; +import { Subscription } from "rxjs"; @Component({ selector: 'app-pago-electronico', @@ -12,6 +13,7 @@ import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-f }) export class PagoElectronicoComponent implements OnInit, OnDestroy { urlQr = `${APP_SETTINGS.apiImagenes}/qr/${APP_SETTINGS.deploy}/${APP_SETTINGS.codigoP}/tienda/${APP_SETTINGS.terminal}`; + subscription: Subscription; constructor( private articuloService: ArticuloService, @@ -28,7 +30,7 @@ export class PagoElectronicoComponent implements OnInit, OnDestroy { pedidoAnombreDe: '' }; dataPago.pedidoAnombreDe = ''; - this.articuloService.pay(dataPago) + this.subscription = this.articuloService.pay(dataPago) .subscribe((res: any) => { this.articuloService.idComanda = res.data; this.router.navigate(['mensaje-final']); @@ -42,6 +44,7 @@ export class PagoElectronicoComponent implements OnInit, OnDestroy { } ngOnDestroy() { + if (this.subscription) this.subscription.unsubscribe(); for (let i = 1; i <= this.modalService.getModalsCount(); i++) { this.modalService.hide(i); } diff --git a/src/app/modules/pago-tarjeta/pago-tarjeta.component.ts b/src/app/modules/pago-tarjeta/pago-tarjeta.component.ts index c37a33f..15008b2 100644 --- a/src/app/modules/pago-tarjeta/pago-tarjeta.component.ts +++ b/src/app/modules/pago-tarjeta/pago-tarjeta.component.ts @@ -3,6 +3,7 @@ import { ArticuloService } from 'src/app/services/articulo/articulo.service'; import { Router } from '@angular/router'; import { BsModalService } from 'ngx-bootstrap/modal'; import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-pago-tarjeta', @@ -11,7 +12,8 @@ import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-f }) export class PagoTarjetaComponent implements OnInit, OnDestroy { timer: any; - @ViewChild('template', {static: true}) public template: TemplateRef; + subscription: Subscription; + @ViewChild('template', { static: true }) public template: TemplateRef; constructor( private articuloService: ArticuloService, @@ -28,7 +30,7 @@ export class PagoTarjetaComponent implements OnInit, OnDestroy { const dataPago = { pedidoAnombreDe: '' }; - this.articuloService.pay(dataPago) + this.subscription = this.articuloService.pay(dataPago) .subscribe((res: any) => { this.articuloService.idComanda = res.data; this.router.navigate(['mensaje-final']); @@ -42,6 +44,7 @@ export class PagoTarjetaComponent implements OnInit, OnDestroy { } ngOnDestroy() { + if (this.subscription) this.subscription.unsubscribe(); if (this.timer) clearTimeout(this.timer); for (let i = 1; i <= this.modalService.getModalsCount(); i++) { this.modalService.hide(i); -- 1.9.1