Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

hostListener

  @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;
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #hostListener
ADD COMMENT
Topic
Name
4+9 =