首页 > 解决方案 > 在角度/节点中将数据从 api 发布到

问题描述

如果我的问题是多余的,我很抱歉,但我已经尝试解决这个问题了 2 天。

我有一个 angular at 表格localhost:4000,我想将它的数据发布到我的 api,localhost:4000/api/scheduled但每次我得到一个 500 错误。

然后这些数据可能会从 api 发送到 mariadb。我可以实现从 mariadb 到 angular 的获取请求,但 post 不起作用。

我精确它,但我认为将表单从角度发布到 api 的错误。

我尝试了很多东西,比如调整标题,通过缩小发送的数据......但没有任何效果。

    onSubmitScheduled() {

        let OndemandScheduledRequest = this.formatRequestScheduled(this.selectedHotel, this.selectedCheckInDate, this.selectedCheckOutDate, this.selectedNumber, this.selectedCurrency, this.selectedReportName, this.selectedUser, this.selectedEmail, this.selectedFormat);
        console.log(OndemandScheduledRequest);
        this.saveScheduledRequest(OndemandScheduledRequest);
        this.openDialog();
      }

    saveScheduledRequest(onDemandScheduledRequest: OnDemandScheduledRequest) {
        console.log(onDemandScheduledRequest);

      /*  var headers = new HttpHeaders();
        headers.append('Content-Type', 'application/form-data');
        */

       return this.http.post('http://localhost:4000/api/scheduled',onDemandScheduledRequest    )

    .subscribe(

           response => {
          debugger;
          console.log(response)
        },
      (err : HttpErrorResponse)=> console.log({
          err
        },))
      }

这是发布在界面中定义的对象(我已导入)的函数:

    export interface OnDemandScheduledRequest {
        id: string,
        user: string,
        email: string,


        reportName: string,
        format: string,
        submissionDate: string,


        Name: string,
        checkIn: string,
        checkOut: string,
        guests: string,
        currency: string,

      status: boolean,

    }

这是使用表单字段创建此接口实例的函数:

    formatRequestScheduled(selectedHotel, selectedCheckInDate, selectedCheckOutDate, selectedNumber, selectedCurrency, selectedReportName, selectedUser, selectedEmail, selectedFormat ) :
        //AS MANY RESULTS AS REQUESTED HORIZONS.
    any{

       let DemandScheduledRequest = {
         id: '1',

         user: selectedUser.toString(),
         email: selectedEmail.toString(),


         reportName: selectedReportName.toString(),
         format: selectedFormat.toString(),
         submissionDate: new Date(),


         Name: selectedHotel.toString(),
         checkIn: selectedCheckInDate,
         checkOut: selectedCheckOutDate,
         guests: selectedNumber.toString(),
         currency: selectedCurrency.toString(),


         status: false,
       }
        return DemandScheduledRequest;
      }

感谢您的任何帮助。

标签: angularapipost

解决方案


推荐阅读