【问题标题】:Angular 8 front-end not sending captured data/fields to Go back-endAngular 8 前端未将捕获的数据/字段发送到 Go 后端
【发布时间】: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 查询中将捕获\编辑的字段用作占位符的值

【问题讨论】:

    标签: angular go angular8


    【解决方案1】:

    在您的 .html 中,您将 ngModel 用于 details,但在您的 component.ts 中您有 detailsData

    在您的component.ts 中,updateDetails 函数有 1 个参数。确保使用console.log 执行该函数,因为您没有在.html 中提供参数

    另外,我不知道您是否希望后端接收字符串。您应该通过put 发送您的数据,而不是JSON.stringify

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 2019-01-25
      • 1970-01-01
      • 2021-06-11
      相关资源
      最近更新 更多