【发布时间】:2018-08-04 14:09:21
【问题描述】:
在我的组件中我有这个
this.authService.addPost(post).subscribe(data => {
if (data.type === HttpEventType.UploadProgress) {
console.log(data);
} else if (data.type === HttpEventType.Response) {
if (data.body.success) {
alert('post added');
this.modalRef.close('Save click');
} else {
alert('an error has occured');
}
}
});
这是我的服务
addPost(post) {
const headers = new HttpHeaders({
// add authorisation
'Authorization': `Bearer ${this.authToken}`
});
return this.httpClient.post<Addpost>('' + this.domain + 'add/addPost', post,
{
reportProgress: true,
observe: 'events',
headers: headers,
});
}
所以我的问题出在控制台中,我得到的是上传文件的总状态,而不是进度。我得到了这样的东西
{type: 1, loaded: 21076, total: 21076}
我尝试了很多参数,但都无济于事
【问题讨论】:
-
你解决过这个问题吗?
-
不,我没有。
-
大家好,你们有没有看到关于这个的文档angular.io/guide/http#listening-to-progress-events
-
嘿,我知道已经晚了,但你解决了吗?
标签: angular http observable angular6 angular-httpclient