Currently, I am in the process of implementing a "Create" function to generate appointments and also include the User ID of the creator. To achieve this, I have set up models for "rendezvous" and "user." However, upon executing the project, I am encountering an error in the console:
core.mjs:7643 ERROR TypeError: Cannot read properties of undefined (reading 'id') at CreateRendezvousComponent_Template (create-rendezvous.component.html:45:9) at executeTemplate (core.mjs:12114:9) at refreshView (core.mjs:11977:13)The error seems to be originating from the HTML of the "create-rendezvous" component:
<label>Etat</label>
<input type="text" class="form-control" id="etat"
[(ngModel)]= "rendezvous.etat" name="etat">
</div>
<div class="form-group">
<label>User ID</label>
<input type="number" class="form-control" id="user.id"
[(ngModel)]= "rendezvous.user.id" name="user.id">
</div>
<button class="btn btn-success" type="submit">Add</button>
</form>
</div>
This is the "Create" function within the "create-rendezvous" component:
saveRendezVous(){
this.rendezvousService.createRendezvous(this.rendezvous).subscribe(data=>{
console.log(data);
this.goToRendezvousList();
},
error=>console.log(error));
}
And here is the function in the Angular service:
createRendezvous(rendezvous:Rendezvous): Observable<Object>{
return this.httpClient.post(`${this.baseUrl}`, rendezvous);
}
Your assistance with this matter is greatly appreciated.