title: Login with Angular error: TypeError: Cannot read property 'length' of undefined
body: <p>I'm trying to do an API to login, but I'm getting this error: </p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'length' of undefined.</p>
  </blockquote>
  
  <p><strong>My login.service</strong></p>
  
  <pre><code>login(username: string, password: string): Observable&lt;HttpResponse&lt;any&gt;&gt; {
      return this.http.post&lt;any&gt;(environment.urlApi + "authenticate",
        null, //body
        {
          headers: Utils.getHeaderLogin(username, password),
          observe: "response"
        }
      ).pipe(
        catchError(this.handleError)
      );
    }
  </code></pre>
  
  <p><strong>utils</strong></p>
  
  <pre><code>private static APP_JSON: 'application/json';
  
  static getHeaderLogin(username: string, password: string) {
      const httpHeaders = new HttpHeaders({
          'Content-Type': this.APP_JSON,
          'user': username,
          'key': password
      });
      return httpHeaders;
  }
  </code></pre>
  
  <p><strong>My login.component</strong></p>
  
  <pre><code>onSubmit(data) {
      console.log(data)
      this.inscricao = this.service.login(data.username, data.password)
        .subscribe((dados: any) =&gt; {
          if (dados &amp;&amp; dados.headers) {
            console.log(dados.headers);
            const keys = dados.headers.keys;
          }
        },
          erro =&gt; this.erro = console.log(erro),
          () =&gt; console.log('complete')
        );
      this.userForm.reset();
    }
  </code></pre>
  
  <p>Using postman all works fine, but my backend don't receive any request, so the problem is in my frontend.<br>
  I've tried to search a lot on the internet, but without success.<br>
  Thank you.</p>