title: How can we get Json web token via angular?
body: <p>I have a rest service in Spring boot application.</p>
  
  <p>I have a method, that accepts username and password as json data and checks this data, if they're true then service return JWT token.</p>
  
  <p><a href="https://i.stack.imgur.com/x0cFT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x0cFT.png" alt="enter image description here"></a></p>
  
  <p>When I call this method via angular, I can't get Authorization token and request send twice.</p>
  
  <p><a href="https://i.stack.imgur.com/l9FOh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l9FOh.png" alt="enter image description here"></a></p>
  
  <p>Why request send twice and how can I get token in angular?</p>
  
  <pre><code>import {Component, OnInit} from '@angular/core';
  import {Payment} from './Payment';
  import {HttpClient, HttpResponse} from '@angular/common/http';
  
  @Component({
    selector: 'app-home',
    templateUrl: './home.component.html',
    styleUrls: ['./home.component.css']
  })
  export class HomeComponent implements OnInit {
  
    title = 'Home';
    constructor(private http: HttpClient) {
    }
  
    ngOnInit() {
  
      this.http.post('http://localhost:8084/login', JSON.stringify({ username: 'mehman', password: 'mehman' }), { observe: 'response' })
        .subscribe((response: HttpResponse&lt;any&gt;) =&gt; { console.log(response); });
    }
  }
  </code></pre>