【发布时间】:2019-09-13 16:11:34
【问题描述】:
我目前正在重写一个应用程序,该应用程序将具有 Angular 8 前端(边学习边编写代码),它将与连接到 MSSQL 数据库的 Go 后端交互。 我可以成功显示数据库中的数据。 但是,当尝试更新接收到的数据时,字段/数据似乎没有被发送到 Go 后端。 我已经使用 Postman 测试了 Go 后端 API,并且效果很好。 关于下面的代码可能有什么问题或我可以做些什么来调试它的任何建议?
rest-api.service.ts
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-edit.component.ts
@Input() detailDetails = { Ref: '', Name: '', Number: '', Trans_Date: '', Amount: '', Type: '', Reason: '', Code: '', Run_Date: ''} Ref = this.actRoute.snapshot.params['Ref'];
detailsData: any = {};
constructor(
public restApi: RestApiService,
public actRoute: ActivatedRoute,
public router: Router
) {
}
ngOnInit() {
this.restApi.getDetails(this.Ref).subscribe((data: {}) => {
this.detailsData = data;
})
}
updateDetails(detailDetails) {
this.restApi.updateDetails(this.Ref, this.detailDetails).subscribe((data: {}) => {
this.router.navigate(['/details-list'])
})
}
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 查询中将捕获\编辑的字段用作占位符的值
【问题讨论】: