发送后端文件和formBuilder

时间:2018-04-04 17:52:45

标签: angular http post

如何发送到后端文件和formBuilder

我的尝试

    save(form) { // form == formBuilder

        const uploadData = new FormData();
        if (this.selectedFile) {
          uploadData.append('myFile', this.selectedFile, this.selectedFile.name);
        }
        this.professorService.save(uploadData,form)
    }

service.ts

save(form,fb) {
    let params: HttpParams = undefined
    params = new HttpParams().set('fb', fb)    
    return this.http.post(`${BE_API}/professor.php?action=save`, form,{ params: params})
      .subscribe((data) => {
        if (data['success'] == 'ok') {
        }
        console.log(data);
      }, (error) => {
      });
  }

在后端,fb(formBuilder)到达字符串" "

输出控制台

array(12) {
  ["fb"]=>
  string(15) "[object Object]"
...
}

0 个答案:

没有答案