title: Angular 2 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header
body: <p>I'm new to Angular2. And I'm trying to call POST method to my .net core API.It's working fine with Postman.But when I call it from my angular 2 service it gives an error.</p>
  
  <p><a href="https://i.stack.imgur.com/l6Ick.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l6Ick.png" alt="enter image description here"></a></p>
  
  <p><strong>This is my api.service.ts</strong>
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import { Injectable } from '@angular/core';
  import { environment } from '../../../environments/environment';
  import { Headers, Http, Response, URLSearchParams } from '@angular/http';
  import { Observable } from 'rxjs/Rx';
  import 'rxjs/add/operator/map';
  import 'rxjs/add/operator/catch';
  
  import { JwtService } from './jwt.service';
  
  @Injectable()
  export class ApiService {
    constructor(
      private http: Http,
      private jwtService: JwtService
    ) {}
  
    private setHeaders(): Headers {
      const headersConfig = {
        'Content-Type': 'application/json',
        'Accept': 'application/json', 
        'Access-Control-Allow-Origin': '*'
      };      
  
      if (this.jwtService.getToken()) {
        headersConfig['Authorization'] = `Token ${this.jwtService.getToken()}`;
      }
      return new Headers(headersConfig);
    }
  
    post(path: string, body: Object = {}): Observable&lt;any&gt; {
     
      return this.http.post(
        `${environment.api_url}${path}`, 
          JSON.stringify(body),
          { headers: this.setHeaders() }
      )
      .catch(this.formatErrors)
      .map((res: Response) =&gt; res.json());
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>body values
  <a href="https://i.stack.imgur.com/OMd7A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OMd7A.png" alt="enter image description here"></a></p>
  
  <p>.net core API mothod
  <a href="https://i.stack.imgur.com/yv6c1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yv6c1.png" alt="enter image description here"></a></p>