Я получил список элементов из моей базы данных mySql, а также кнопку «Изменить».
Когда я нажал «Изменить» (по идентификатору), я хочу увидеть все поля, заполненные данными.
Но у меня есть только в моей консоли: undefined
Если я проверил мой 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"
}
]