Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230107

How to fix my ion badge for cart is not updating in real time and requires navigation from other pages to be updated?

$
0
0

whenever i add any product in the cart, the shopping cart icon doesn’t update in real time to show that a product is added but needs a refresh of the view by navigating to any other page and coming back then only the ion -badge value is set 1.

<button ion-button icon-only (click)="cart()">    
<ion-icon name="cart"></ion-icon>
<ion-badge id="notifications-badge" style="font-size:1rem" *ngif="ccount">{{ccount}}</ion-badge>
</button>


//SETTING CART LENGTH

    this.storage.get('products').then((data) => {
      if(data != null)
        this.ccount = data.length;
      else
        this.ccount = 0;
    });

//code after pressing the add to cart button

showAlert() {
      let alert = this.alertCtrl.create({
        title: 'Product Added!',
      subTitle: 'Added To Cart Successfully!',
      buttons: ['OK']
    });
this.updateStorage(this.productdetail).catch(reason = console.error(reason));
      alert.present();
      this.changeDetector.detectChanges();
  }

Viewing all articles
Browse latest Browse all 230107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>