Angular 8前端未将捕获的数据/字段发送到后端
我目前正在重写一个应用程序,该应用程序将有一个Angular 8前端(作为我的代码学习),该前端将与连接到MSSQL数据库的Go后端交互。 我可以成功显示数据库中的数据。 但是,当尝试更新接收到的数据时,看起来字段/数据没有发送到Go后端。 我已经使用Postman测试了Go后端API,效果很好。 关于下面的代码可能有什么问题,或者我可以做些什么来调试它,有什么建议吗 rest-api.service.tsAngular 8前端未将捕获的数据/字段发送到后端,angular,go,angular8,Angular,Go,Angular8,我目前正在重写一个应用程序,该应用程序将有一个Angular 8前端(作为我的代码学习),该前端将与连接到MSSQL数据库的Go后端交互。 我可以成功显示数据库中的数据。 但是,当尝试更新接收到的数据时,看起来字段/数据没有发送到Go后端。 我已经使用Postman测试了Go后端API,效果很好。 关于下面的代码可能有什么问题,或者我可以做些什么来调试它,有什么建议吗 rest-api.service.ts httpOptions = { headers: new HttpHeaders({
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
//'Content-Type': 'Application-Token : this.getToken()'
})
}
updateDetails(ref, details): Observable<Details> {
return this.http.put<Details>(this.apiURL + '/details-edit/' + ref, JSON.stringify(details), this.httpOptions)
.pipe(
retry(1),
catchError(this.handleError)
)
}
details-component.html
<div class="form-group">
<input type="text" [(ngModel)]="details.Run_Date" class="form-control" placeholder="Run_Date">
</div>
<div class="form-group">
<button class="btn btn-success btn-lg btn-block" (click)="updateDetails()">Update Details</button>
</div>
更新详细信息
我希望捕获的\编辑的字段用作我的GO MSSQL查询中占位符的值。在您的
.html
中,您使用的是ngModel作为详细信息
,但在您的组件.ts中,您有详细数据
在组件.ts
中,updateDetails
函数有一个参数。确保使用控制台.log
执行该函数,因为在.html
另外,我不知道您是否希望后端接收字符串。您应该通过put
发送数据,而不使用JSON.stringify
我希望这有帮助
<div class="form-group">
<input type="text" [(ngModel)]="details.Run_Date" class="form-control" placeholder="Run_Date">
</div>
<div class="form-group">
<button class="btn btn-success btn-lg btn-block" (click)="updateDetails()">Update Details</button>
</div>