答案 0 :(得分:0)
在您的.html文件中:
<button (click)="increase()">increase</button>
<ion-item>{{myNumber}}</ion-item>
在.ts文件中,在构造方法之前定义
myNumber: number = 0;
然后在构造函数中编写此函数:
increase(){
this.myNumber+=1;
}
答案 1 :(得分:0)
.ts
export class yourPageClass{
count: number = 0; //Here you'll initialize it just once and we'll access it in the function
countup()
{
this.count++; //instead of reinitializing, we are using already initialized variable
console.log(JSON.stringify(this.count));
}
在html文件中
<button (click)="countup()">increase</button>
<ion-item>{{number}}</ion-item>
传递值
this.navCtrl.push(page2,{
item:count
});
访问该计数
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page2',
templateUrl: 'page2.html',
})
export class Page2 {
value:any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.value = navParams.get('item');
}
ionViewDidLoad() {
console.log('ionViewDidLoad EmiCalPage');
}
}