Hi i am currently trying to build an Angular project that is based around a form. The form data is saved to a MySQL database, a search function is supposed to a retrieve a specific dataset that is displayed in a separate view where it can be either updated or deleted. The search offers a list of possible results as links and on selecting a specific link the app should be routing into the view that shows the dataset.
Here is where I am stuck: Both saving and searching works out fine. When selecting a link from the search result the app routes to the correct view but the corresponding input fields are empty. If I use the inspection tool of the browser I can see that an XHR containing the correct dataset is delivered.
I am quite new at programming in general and at my end of my wit.
Here are all the code snippets I think might be relevant:
excerpt from detailview.html (the form is longer, but missing elements are structured in the same way):
<div *ngIf="patient">
<h2> Meine Daten:</h2>
<div>
<label for="patientendaten-titel">Titel: </label>
<input id="patientendaten-titel" [(ngModel)]="patient.titel" placeholder="titel">
</div>
<div>
<label for="patientendaten-anrede">Anrede: </label>
<input id="patientendaten-anrede" [(ngModel)]="patient.anrede" placeholder="anrede">
</div>
<div>
<label for="patientendaten-vorname">Vorname: </label>
<input id="patientendaten-vorname" [(ngModel)]="patient.vorname" placeholder="vorname">
</div>
<div>
<label for="patientendaten-name">Nachname </label>
<input id="patientendaten-name" [(ngModel)]="patient.name" placeholder="name">
</div>
</div>
detailview.component.ts:
patient: Patientendaten | undefined;
getPatient():void{
const id = parseInt (this.route.snapshot.paramMap.get('id')!);
this.formService.getPatientId(id).subscribe(patient=> this.patient = patient);
}
form.service.ts:
private formUrl2 = 'http://localhost/api/getId.php'
public getPatientId (id: number): Observable<Patientendaten>{
const url = `${this.formUrl2}/${id}`;
return this.http.get<Patientendaten>(url);
}
getId.php:
<?php
// returns data of patient selected by Id as JSON
require 'connect_db.php';
$url= $_SERVER['REQUEST_URI'];
$id= basename($url);
$sql = "SELECT id, titel, anrede, vorname, name, strasse, hausnr, plz, ort, telefonnr, email
FROM personendaten
WHERE id = '$id'";
$result = mysqli_query($con, $sql);
echo json_encode ($result->fetch_all(MYSQLI_ASSOC));
$con->close();
?>
edit:show declaration of patient variable in detailview.component.ts