簡體   English   中英

如何計算LoadingController在2個事件之間的時間-present()和dismiss()-IONIC 2

[英]How to calculate time for LoadingController between 2 events- present() and dismiss() -IONIC 2

我已經在我的組件上實現了加載控制器,該控制器從json api帶來數據,我希望獲得計算得出的在頁面上帶來數據的時間。

請找到我已實現listproduct.ts OnInitlistproduct.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM