繁体   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