[英]How to calculate time for LoadingController between 2 events- present() and dismiss() -IONIC 2
我已經在我的組件上實現了加載控制器,該控制器從json api
帶來數據,我希望獲得計算得出的在頁面上帶來數據的時間。
請找到我已實現listproduct.ts
OnInit
的listproduct.ts
export class ListproductPage implements OnInit{
public list = [];
loading;chkfromservice;
constructor(private _listProduct : ListproductService,private _deleteProduct : DeleteProductService,
public navCtrl: NavController,public navParams: NavParams,public loadingCtrl: LoadingController) {
this.loading = this.loadingCtrl.create({
content: 'Please wait...'
});
}
ngOnInit() {
this.loading.present();
this._listProduct.listProduct().subscribe(data => {
this.list = data;
console.log(this._listProduct.checkfromservice);
this.chkfromservice = this._listProduct.checkfromservice;
console.log(data[0].NAME);
this.loading.dismiss();
});
}
請注意,我需要計算
this.loading.present();
之間的this.loading.present();
和this.loading.dismiss();
您可以在啟動加載程序之前存儲日期,也可以在關閉加載程序之后再次存儲日期。 然后,您可以獲取兩個日期之間的差額。 這是示例代碼。
ngOnInit() {
let start = new Date(); // Get the date just before presenting your loader
this.loading.present();
this._listProduct.listProduct().subscribe(data => {
this.list = data;
console.log(this._listProduct.checkfromservice);
this.chkfromservice = this._listProduct.checkfromservice;
console.log(data[0].NAME);
this.loading.dismiss();
let end = new Date(); // Get the date just after dismissing your loader
let diff = (end.getTime() - start.getTime()); // Get the time difference in milliseconds
console.log(diff);
});
}
有關如何計算時差的更多詳細信息,請參考此答案 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.