【发布时间】:2017-12-09 07:21:43
【问题描述】:
我希望在单击按钮时动态更新徽章值。
tabs.html
...
<ion-tab [root]="tab1Root" tabTitle="Product" tabIcon="search"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="Cart" tabIcon="cart" tabBadge="{{cartCount}}" tabBadgeStyle="danger"></ion-tab>
...
tabs.ts
export class TabsPage {
...
cartCount = 0;
tab1Root = ProductPage;
tab2Root = CartPage;
...
}
product.html
<button ion-button full (click)="updateCart('add', p.id)">Buy Now</button>
product.ts
export class ProductPage {
...
updateCart(action, id) {
let cartCount = 1;
let alert = this.alertCtrl.create({
title: 'Success!',
subTitle: 'You have added 1 product to the cart.',
buttons: ['OK']
});
alert.present();
}
...
}
正如我所说,let cartCount = 1; 什么都不做。我一直在寻找解决方案,但其中大多数是针对 Ionic 1 或 AngularJS,这对我没有任何帮助。
【问题讨论】:
标签: javascript angular typescript ionic2 ionic3