问题描述
我正在尝试为上传添加进度条并出现此错误。 并且 event.type 未定义。
请帮我找到解决方案。谢谢
我附上了我已经完成的代码。
HttpRequest 代码
uploadfile(file: any): Observable<HttpEvent<any>>{
return this.InfoService.getId().pipe(
concatMap((result) => {
return this.schemaService.getSchema().pipe(schema => {
const url = '/url';
return this.http.post(url,file,{headers: this.headers,reportProgress: true});
}).toPromise().then((resolved) => {
this.successMessage('Upload Success',MessageIcon," uploaded successfully");
})
}));
}
订阅方式:
uploadfile(){
const formData = new FormData();
formData.append('file',this.uploadForm.get('item').value);
this.uploadService.uploadfile(formData).subscribe((event : HttpEvent<any>) => {
console.log(event)
switch (event.type) {
case HttpEventType.UploadProgress:
this.progress = Math.round(event.loaded / event.total * 100);
console.log(`Uploaded! ${this.progress}%`);
break;
case HttpEventType.Response:
console.log('successfull!',event.body);
setTimeout(() => {
this.progress = 0;
},1500);
}
})
}
解决方法
-
我不确定您想用
$chart->setOptions([ 'responsive' => true,'legend' => ['display' => false],'title' => [ 'display' => true,'text' => 'Title of the graph','fontSize' => 16 ],'scales' => [ 'yAxes' => [ 'title' => [ 'display' => true,'text' => 'Title for y Axes',] ],],]);
函数的schema
参数做什么。pipe
将 RxJS 运算符作为参数。从使用情况来看,我假设您想在这里使用像pipe
这样的映射运算符。 -
函数的返回类型声明为
concatMap
。但是您正在使用Observable<HttpEvent<any>>
函数将 Observable 转换为 Promise。您可以改用toPromise()
运算符。
试试下面的方法
tap