i'm trying to implement a "Create" function to create appointements and i'm also adding the User id who created the appointement,so i created a model of "rendezvous" and "user" but i when i execute the project the console shows an error of 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) at refreshComponent (core.mjs:13073:13) at refreshChildComponents (core.mjs:11767:9) at refreshView (core.mjs:12027:13) at refreshComponent (core.mjs:13073:13) at refreshChildComponents (core.mjs:11767:9) at refreshView (core.mjs:12027:13) at refreshEmbeddedViews (core.mjs:13027:17)
the error comes from the HTML of "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">Ajouter</button>
</form>
</div>
this is my "Create" function in the "create-rendezvous" component
saveRendezVous(){
this.rendezvousService.createRendezvous(this.rendezvous).subscribe(data=>{
console.log(data);
this.goToRendezvousList();
},
error=>console.log(error));
}
and this is my function in the angular service
createRendezvous(rendezvous:Rendezvous): Observable<Object>{
return this.httpClient.post(`${this.baseUrl}`, rendezvous);
}
i appreciate your help.