我需要使用angular 2在HTTP get request的帮助下显示来自nodejs后端的图像 那是我的帖子图片代码
<input id="cin" name="cin" type="file" (change)="fileChangeEvent($event)"
placeholder="Upload a file..." multiple/>
组件代码
onSubmit(){
this.dataService.postproductcreate(this.model).subscribe(response =>console.log(response),(error) => console.log(error));
// const fd=new FormData();
// fd.append('file',this.selectedFile,this.selectedFile.name)
// this.dataService.uploadimage(fd).subscribe(response =>console.log(response),(error) => console.log(error)
// );
const formData: any = new FormData();
const files: Array<File> = this.filesToUpload;
console.log(files);
for(let i =0; i < files.length; i++){
formData.append("uploads[]", files[i], files[i]['name']);
}
console.log('form data variable : '+ formData.toString());
this.dataService.uploadimage(formData).subscribe(response =>console.log(response),(error) => console.log(error));
// window.location.reload();
}
service.ts
uploadimage(data){
return this._http.post(this.url,data,{withCredentials:true}).map(res=>res.json());
}
现在,我想从nodejs后端获取图像并以角度2显示图像,但我不知道该怎么做。