You can easily achieve this with:
npm i angular-progress-http
After importing the module, you can now add below it to your app.module.ts or wherever you stack your app modules in your application.
You will import this (in app.module.ts):
import { HttpModule } from '@angular/http';
import { ProgressHttpModule } from 'angular-progress-http';
Still in your app.module.ts
at @NgModule
@NgModule({
imports: [
HttpModule,
ProgressHttpModule
]
})
Then in your component file (whatever.component.ts), where you want to use it. You can place this:
import { ProgressHttp } from 'angular-progress-http';
Then implement like this:
constructor(private http: ProgressHttp) {}
onSubmit(): void {
const _formData = new FormData();
_formData.append('title', this.title);
_formData.append('doc', this.doc);
this.http.withUploadProgressListener(progress => { console.log(`Uploading ${progress.percentage}%`); })
.withDownloadProgressListener(progress => { console.log(`Downloading ${progress.percentage}%`); })
.post('youruploadurl', _formData)
.subscribe((response) => {
console.log(response);
});
}