Javascript 几个平面图在保存时导致错误(Typescript)
我有一个角度组件上传文件到服务器 下面是它的保存方法Javascript 几个平面图在保存时导致错误(Typescript),javascript,angular,typescript,Javascript,Angular,Typescript,我有一个角度组件上传文件到服务器 下面是它的保存方法 private saveFileAndData(): void { this._propertyService .createOrEditProperty(this.property) .pipe( flatMap(r => this._fileUploadService.uploadFiles(this.getUploadUrl(r), this.files)),
private saveFileAndData(): void {
this._propertyService
.createOrEditProperty(this.property)
.pipe(
flatMap(r => this._fileUploadService.uploadFiles(this.getUploadUrl(r), this.files)),
flatMap(r => this._fileUploadService.uploadFiles(this.getFloorPlanUploadUrl(r), this.floorPlans)),
finalize(() => {
this.saving = false;
})
)
.subscribe(() => {
this.notify.info(this.l('SavedSuccessfully'));
this.close();
this.modalSave.emit(null);
});
}
当我有一个平面图时,一切都很好,现在我需要通过保存加载不同的文件。所以我有两张平面图。但现在我有了这个错误
如果我只留下一张平面图,一切都好
这里是文件上传服务
@Injectable()
export class FileUploadService {
constructor(private _http: HttpClient) {}
uploadFiles(url: string, filesToUpload: any[]): Observable<any> {
if (filesToUpload.length) {
const formData: FormData = new FormData();
for (let file of filesToUpload) {
formData.append('file', file);
}
let headers = new HttpHeaders();
return this._http.post(url, formData, { headers: headers });
}
return of(null);
}
}
@Injectable()
导出类FileUploadService{
构造函数(私有的_http:HttpClient){}
上传文件(url:string,filesToUpload:any[]):可观察{
if(filesToUpload.length){
const formData:formData=new formData();
for(让文件的文件加载){
formData.append('file',file);
}
let headers=新的HttpHeaders();
返回这个。http.post(url,formData,{headers:headers});
}
返回(空);
}
}
如何解决此问题?从您的屏幕截图来看,您的一个uploadFiles调用似乎有一些错误行为,使得对上载端点的调用带有“null”!是的,第一个获取id,第二个获取[object object]@wessamyaacobc您可以制作stackblitz链接演示来重现这个问题吗?我猜不会,因为组件很大,并且有很多依赖项@wessamyaacobtry在返回这个之前添加console.log(formData)。_http.post(url,formData,{headers:headers});确保发送的参数正确