【问题标题】:Update the value in local storage and display it on web page without refreshing the page更新本地存储中的值并显示在网页上而不刷新页面
【发布时间】:2020-09-06 17:11:25
【问题描述】:

我目前正在从事 Angular 8 项目。我有一个变量 'cartproductitems',我想让它尽快更新这个变量 当用户将新产品添加到购物车中时。使其中的项目数 购物车已更新。一切都很好,除了每次我 每当用户将新产品添加到购物车时刷新我的页面。

我的 HTML 代码

   <div class="fw-700 mainNavCol" *ngIf="brand_Name!='Pipasha Restaurant'">
        <div class="fa-4x" style="position: relative !important;">
            <button class="btn-cart" (click)="callCheckout()"><i class="fa fa-shopping-cart"></i>
              <span class="hidden-phone">My Trolley</span>
            </button>
            <span class="fa-layers-counter" style="background:Tomato; font-size: xx-large;">{{(""+cartProductItems)?.length}}</span>
        </div>
      </div>

我的 TS 代码

cartProductItems: number;
this.cartProductItems = this._requestService.getProductCartItems();
    console.log('cartProductItems -> '+this.cartProductItems);
  callCheckout() {
    let isTable: boolean = JSON.parse(this._local.get('isTable'));
    if(isTable){
      this._requestService.tableCheckout(this.cartProductItems);
    }
    else{
      this._requestService.checkout(this.cartProductItems);
    }
    console.log('callCheckout -> isTable -> '+isTable);
  }

【问题讨论】:

  • 请用您添加产品的代码更新问题

标签: javascript angular typescript angular8 angular-local-storage


【解决方案1】:

您是否尝试为您的按钮指定按钮类型?如果没有定义,至少有一些浏览器将它们用作提交,这可能会导致向服务器发出请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多