I've implemented the addUser(newUser)
function in my sign-in.service.ts file like this:
addUser(newUser)
{
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
let body = JSON.stringify(newUser);
this.httpclient.post('http://localhost:3000/api/signup', body, httpOptions).subscribe(res=>{
console.log(res);
return res;
});
}
The console output after execution is
{msg: "successfully added", status: 200}
.
However, when I call the addUser(newUser)
function from the sign-in.component.ts file using the code below:
addUser()
{
console.log(this.first_name,this.last_name,this.userName,this.email);
let newUser = {
"first_name":this.first_name,
"last_name":this.last_name,
"username":this.userName,
"email":this.email
}
console.log(this.signService.addUser(newUser));
}
The console output shows undefined
. Can someone explain why? Your assistance would be greatly appreciated. Thank you.