【发布时间】:2019-11-01 04:28:39
【问题描述】:
我从我的数据库 mySql 以及“编辑”按钮中获得了项目列表。 当我单击编辑(按 id)时,我想查看由数据填充的所有字段。 但我只有在我的控制台:未定义 如果我通过邮递员测试了我的 api,它可以正常工作。
这是我获取列表的方式。
{
const id = this.actRoute.snapshot.paramMap.get('id');
this.studentApi.GetStudent(id).subscribe((res: any) => {
console.log(res.data);
this.subjectArray = res.data;
console.log(this.subjectArray);
this.studentForm = this.fb.group({
id: [res.id, [Validators.required]],
domain_id: [res.domain_id, [Validators.required]],
source: [res.source, [Validators.required]],
destination: [res.destination]
});
});
}
还有我的 api.service.ts
GetStudent(id): Observable<any> {
const API_URL = `${this.endpoint}/read-student/${id}`;
return this.http.get(API_URL, { headers: this.headers })
.pipe(
map((res: Response) => {
return res || {};
}),
catchError(this.errorMgmt)
);
}
还有我的路线
studentRoute.get('/read-student/:id', (request, response) => {
const id = request.params.id;
con.query('SELECT * FROM students WHERE id = ?', id, (error, result) => {
if (error) throw error;
response.send(result);
});
});
'邮递员'有回应
[
{
"id": 5,
"domain_id": 2,
"source": "tester0700@test.pl",
"destination": "testw@test.pl"
}
]
【问题讨论】: