从Angular 8发布到Node.JS的最佳方法是什么
我在使用此功能时会遇到一些麻烦。到目前为止,我使用GET方法,现在我需要将一些数据发布到服务器。
这是一个GET请求:
getReports(userID) {
return this.http.request<Reports[]>('GET', this.baseUrl + this.REPORTS_API + '/' +
this.USER_API + '/' + userID, { responseType: 'json' });
}
现在我需要发布数据
createNewReport(companyID, type, year){
return this.http.request<[]>('POST', this.baseUrl + this.REPORTS_API, { responseType: 'json'});
}
我应该将数据放在哪里?
回答如下:您需要将数据传递为,
createNewReport(companyID, type, year){
const data = JSON.stringify({companyId: companyID, type: type});
return this.http.post(this.baseUrl + this.REPORTS_API, data , { responseType: 'json'});
};
从Angular 8发布到Node.JS的最佳方法是什么
我在使用此功能时会遇到一些麻烦。到目前为止,我使用GET方法,现在我需要将一些数据发布到服务器。
这是一个GET请求:
getReports(userID) {
return this.http.request<Reports[]>('GET', this.baseUrl + this.REPORTS_API + '/' +
this.USER_API + '/' + userID, { responseType: 'json' });
}
现在我需要发布数据
createNewReport(companyID, type, year){
return this.http.request<[]>('POST', this.baseUrl + this.REPORTS_API, { responseType: 'json'});
}
我应该将数据放在哪里?
回答如下:您需要将数据传递为,
createNewReport(companyID, type, year){
const data = JSON.stringify({companyId: companyID, type: type});
return this.http.post(this.baseUrl + this.REPORTS_API, data , { responseType: 'json'});
};