我已经在我的组件上实现了加载控制器,它带来了来自json api
的数据,我希望实现计算在页面上显示数据的时间。
请找到我已实施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();
});
}
请注意,我需要计算
之间的time.microsecondsthis.loading.present();
和this.loading.dismiss();
答案 0 :(得分:1)
您可以在启动装载机之前存储日期,并在解除装载机之后再次存储。然后,您可以获得两个日期之间的差异。这是一个示例代码..
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);
});
}
有关如何计算时差的详细信息,请参阅this answer。