【发布时间】: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