title: Angular - FormGroup Display json errors from server Rest Api
body: <p>I have a REST API server with the php framework Symfony that return this kinds of messages :</p>
  
  <pre><code>{
    "code": 400,
    "message": "Validation Failed",
    "errors": {
      "children": {
        "email": {
          "errors": [
            "This address mail is already used."
          ]
        },
        "name": {
          "errors": [
            "This name is too short."
          ]
        },
        "password": []
      }
    }
  }
  </code></pre>
  
  <p>And on the front side with Angular FormGroup i have this code:</p>
  
  <pre><code>import { Component } from '@angular/core';
  import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  import { Router } from '@angular/router';
  
  import { RegisterService } from './register.service';
  
  @Component({
    selector: 'app-authentication',
    templateUrl: './authentication.component.html',
  })
  export class AuthenticationComponent {
      loginForm: FormGroup;
      error: string = '';
  
      constructor(
          private formBuilder: FormBuilder, 
          private registerService: RegisterService, 
          private router: Router
      ) {
          this.loginForm = formBuilder.group({
              'name': ['', Validators.required],
              'email': ['', Validators.required],
              'password': ['', Validators.required]
          });
      }
  
      onSubmit() {
          this.authenticationService
              .authenticate(this.loginForm.value)
              .subscribe(
                  data =&gt; { 
                      localStorage.setItem('id_token', data.token);
                      this.router.navigate(['post']); 
                  },
                  error 
                  =&gt; 
                  // Do something
                  // Display server json errors in the corresponding fields
              );
      }
  }
  </code></pre>
  
  <p>How can I get each error message from REST API and display under the corresponding field ?</p>
  
  <p>Thanks you for your help</p>