我有一ionic 2
堂课:
export class SettingsPage {
public num = 2;
public num1 = 3;
constructor(public navCtrl: NavController, public navParams: NavParams,
public storage: Storage) {
storage.ready().then(() => {
// Or to get a key/value pair
storage.get('num').then((val) => {
if (val != null) {
this.num = val;
} else {
this.num = 2;
}
})
});
}
最佳做法是什么?有没有办法监听任何变量(num
,num1
)的任何变化,然后将值设置回存储以保持它?