I create my own upload file component using XMLHttpRequest and everything works fine... The only issue that I have is that I create a callback method which update the progress of the upload so the user can see the percentage.
If I do a consolo.log() of the progrees, I can see how it increase from 0 to 100.
But the screen doesn't reflect that... I have this function in that component:
ngOnChanges(){
if(this.progress == 100){
this.progress = 0;
this.uploading = false;
}
}
And I have a method to get the latest value of the progress (which is fired from the parent component)
public updateProgress(progress : number){
this.progress = progress;
console.log(this.progress);
if(this.progress == 100)
this.uploading = false;
}
And if the template I have
<div *ngIf="uploading" class="uploading">
<progressbar [max]="100" [value]="progress"><span style="color:white; white-space:nowrap;">{{progress}} / {{100}}</span></progressbar>
</div>
So the progress bar is not increasing the progress even when in the console I can see that the value is of 'progress' changing..
But after long time, I discover that if do a click with the mouse in ANY section of the screen the ngOnChange is fired, and the progress bar is updated... So If I start doing clicks while the file is being upload I'm able to see the progress...
Inject
and after you update
progress
, callor
alternatively you can inject
NgZone
and do the update with
This causes change detection to run when Angular code is called from outside Angular in a way that Angular isn't able to recognize it.