I am facing an issue with the code in my ty file:
onSubmit(form: NgForm){
console.log('Executed')
let data = `
name: ${form.value.name},
email: ${form.value.email},
specialty: ${form.value.specialty},
password:${form.value.password}
`;
this.http.post(`${ this.apiURL }/auth/register_lawyer`, data)
.subscribe(
result => {
console.log(result)
},
error => {
if(error.status == 400) {
console.log(error);
}
}
)
}
I am looking for a way to convert the received data from the form into JSON format. For example:
data ={
"name":"Andrew",
"email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e89c8d9b9c8da880879c85898184c68b8785">[email protected]</a>",
"specialty":"developer,
"password":"1234"
}
I need to send the data in JSON format via Post to my API, but I haven't found a solution yet. I attempted using JSON.stringify, however it did not work.