Reputation: 2515
I have implemented loading controller on my component which brings data from json api
, i wish to achieve the time calculated to bring the data on the page.
Please find the code i have implemented OnInit
of 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();
});
}
Please note, i need to calculate the time.microseconds between
this.loading.present();
andthis.loading.dismiss();
Upvotes: 0
Views: 275
Reputation: 3031
You can store the date just before starting your loader and again just after dismissing your loader. You can then get the difference between the two dates. Here's a sample code..
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);
});
}
Refer to this answer for more details on how the time difference is calculated.
Upvotes: 1