how to upload data with other form elements

时间:2019-01-18 18:17:28

标签: angular file-upload angular6

enter image description hereI have a form in angular. I want to post the data in this form. There are 4 file uploads. How can I post the entire form together with the file.

export class TrackDetailComponent implements OnInit, AfterViewInit { 
    public data = new FormData();

   constructor(
        @Inject('TrackService') public trackService: ApiService<Track> ) {
    }

handleFileInput(files: FileList, name) {
    this.data.append(name, files.item(0));
}

saveOrCreate(valid) {
     if (valid)
    {

        this.data.append('trackName', this.track.trackName);
        this.data.append('trackPerformerId', this.track.trackPerformerId+ '');
        this.data.append('trackGenreId', this.track.trackGenreId + '');
        this.data.append('trackYear', this.track.trackYear + '');
        //this.data.append('listDateTime', this.track.listDateTime.toLocaleString("en-US"));
        this.data.append('fizyUrl', this.track.fizyUrl);

        console.log(this.data);
        console.log(this.track);





         this.trackService.getService().all(this.trackService.getApiUrl()).post(this.data ).subscribe((data) => {
      ......

0 个答案:

没有答案