📜  hostListener - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:34.393000             🧑  作者: Mango

代码示例1
@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;