Angular http.post nested json

Issue

I’m working with Angular5 and Symfony 3.4 with FOSUserBundle.

I have something like :

register(username: string, email: string, first: string, second: string)
{
  return this.appHttp.post('register', {username, email, first, second}).subscribe(
    data => {
       this.appHttp.logRequest(data);
    }
  );
}

And what i need to send to API is a formated json like :

{
  "email": "email@test.com",
  "username" : "userTest",
  "plainPassword" : {
    "first" : "123",
    "second": "123"
   }
}

Currently, my json looks like :

{
  "email": "email@test.com",
  "username" : "userTest",
  "first": "123",
  "second": "123",
}

How can i post the required json ?

Thanks!

Solution

Just Change :

{username, email, first, second}

To

{username, email, plainPassword : {first, second} }

Answered By – Vivek Doshi

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.