HosterListener
@HostListener('document:visibilitychange', ['$event'])
visibilitychange() {
if (this.cartProducts && this.isCartProductsChanged) {
const blob = new Blob([JSON.stringify(this.cartProducts)], { type: 'application/json' });
navigator.sendBeacon("http://localhost:3000/api/shopping-online/get-beacon", blob)
this.isCartProductsChanged = false;
}
}
public cartProducts: CartItem[] = [];
public isCartProductsChanged: boolean = false;
Ugly Unicorn