我可以将文件传递到文件夹,但是不能将其ID传递给它。我正在使用ng2-file-upload。我正在mat-dialog框内执行此上传操作我在对话框中获取了spf id,但不知道如何将其发送到URL。还有其他方法可以发布带有ID的文件吗?它给this.attachment列表未定义 码 html:
<button type="button" (click)="item.upload()"><i class="fa fa-upload" aria-hidden="true"></i></button>
ts:
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { Http,Response,Headers } from "@angular/http";
import { DialogService } from '../dialog.service';
import { FileSelectDirective, FileUploader} from 'ng2-file-upload';
import { ActivatedRoute, Router } from '@angular/router';
import {saveAs} from 'file-saver';
const uri = 'http://localhost:3000/file/upload/';
@Component({
selector: 'app-upload-pdf',
templateUrl: './upload-pdf.component.html',
styleUrls: ['./upload-pdf.component.css']
})
export class UploadPdfComponent implements OnInit {
id =""
url : string ;
attachmentList : any[];
uploader: FileUploader;
constructor(private routes : ActivatedRoute , public dialogRef :MatDialogRef<UploadPdfComponent>,private dialog: DialogService,
@Inject(MAT_DIALOG_DATA) public data: any)
{
this.id = this.data.id;
this.url = `${uri}/${this.id}`;
this.uploader = new FileUploader({url : this.url});
this.uploader.onCompleteItem = (item:any,response:any,status:any,headers :any)=>{
this.attachmentList.push(JSON.parse(response));
}
}
ngOnInit() {
let body : any = {
"Spf_id":this.id
}
console.log("SPF_id inside upload", body)
}
}
答案 0 :(得分:0)
您可以在此处使用字符串文字功能。 编辑:在构造url字符串后创建对象
const uri = "http://localhost:3000/file/upload";
private url: string;
uploader: FileUploader;
ngOnInit() {
this.url: `${uri}/${this.id}`;
this.uploader = = new FileUploader({url : this.url});
let body : any = {
"Spf_id":this.id
}
console.log("SPF_id inside upload", body)
}