I am working with a select list that contains names, and I need to extract the name instead of the ID in order to insert it into the database. Below is my TypeScript file:
selectUser() {
this.UtilisateurService.findAll().then((res) => {
let id = '';
this.listUser = res.map(function (obj: any) {
return {
id: obj.id,
text: obj.username,
};
});
this.listUser.splice(0, 0, {
id: 'empty',
text: '-'
});
if (id !== '') {
this.idUser = id;
}
});
}
// I want to set the value of this.nameUser as obj.username:
nameUser:string;
onSubmit() {
this.submitted = true;
if(this.messageForm.valid) {
this.success = true;
let obj = this.messageForm.value;
obj.id_examen = this.idExamen;
obj.id_coach=sessionStorage.getItem('id');
obj.id_cible=this.idUser;
-------> obj.username=this.nameUser;
this.coachingService.addLigneExamen(obj).then(res => {
if (res === true) {
this.closemodal()
}
this.closemodal()
});
}
}