angular material how to show spinner during an synchronous intensive task -
i want show spinner during execution of synchronous task. set showspinner = true
before task starts , showspinner=false
after finishes. however, spinner doesn't show. think because expensive task block dom update *nfif="showspinner
shows spinner. how fix this? thinking of using lifecycle hooks not sure how to.
updateimagedata() { if (this.cropsizechanged) { this.showspinner = true; var imgdata = this.cropper.getcroppedcanvas().todataurl(); //**expensive** this.editedimage = imgdata; this.cropsizechanged = false; this.showspinner = false; } console.log("updated imagedata"); if(this.istaggableimage) { settimeout(() => {this.croppedimageboundingrect = this.croppedimageref.nativeelement.getboundingclientrect();}, 100); } }
the reason why spinner not showing setting false straight away after making expensive call. can try 2 following things
- if expensive call returns callback or promise should set false in call back. in nagular use observable therefore place set
this.showspinner = false
inside subscribe. try code below
public updateimagedata(){ this.showspinner = true; urthing.expensivecall() settimeout()=>{ this.showspinner = false; },3000); }
Comments
Post a Comment