Is there a more efficient way to get all the input values ββand place them in the appropriate location in my object (localStorage) without having to individually retrieve them as shown in the code below?
Below is the function I currently use to update information:
updateContact() {
if (this.onSubmit()) {
this.eleveService.apiUpdateEleve(this.token, this.registerForm.get("firstName").value, this.registerForm.get("lastName").value
).subscribe((data: any) => {
// Retrieve form information
this.student['contact']['us_firstname'] = this.registerForm.get("firstName").value;
this.student['contact']['us_lastname'] = this.registerForm.get("lastName").value;
// this.language = this.student['us_lang']
this.student['us_lang'] = this.lang
this.translate.use(this.student['us_lang']);
// Update the object
localStorage.setItem("student", JSON.stringify(this.student));
console.log('updated', this.student)
this.navCtrl.navigateRoot('/e-tabs/explorer');
})
}
}
This is the structure of my Object :
OBJECT :
contact:
country: {id: "BE", name: "Belgium"}
login: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee828f9d9aae828f9d9ac08c8b">[email protected]</a>"
newsletter: "1"
prest_feedback: "1"
us_address: "Rue des polders 13"
us_city: "Uccle"
us_email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfabbaacab9fabbaacabf1bdba">[email protected]</a>"
us_firstname: "Munir"
us_gsm: "0485001128"
us_id: "5c9b35d8b4dd1"
us_lang: "fr"
us_lastname: "Nahman"
us_zip: "1180"
[Object][1]
[Front-end of the page][2]
[1]: https://i.sstatic.net/SmxSZ.jpg
[2]: https://i.sstatic.net/oknZd.jpg