title: How to resolve CORS issue in Angular 12?
body: <p>I am working on an Angular project and I have login page and during submitting login API, I am facing CORS error. I am attaching screenshot of it also. Any suggestion would be appreciated.</p>
  <pre><code> API Service.ts:
  
             constructor( private http: HttpClient ) { }
                httpOptionsPost = {
                  headers: new HttpHeaders({
                    'Content-Type': 'application/json',
                    'Access-Control-Allow-Origin': '*',
                    'Access-Control-Allow-Credentials': 'true',
                    'Access-Control-Allow-Methods' : 'GET, POST, OPTIONS',
                    'Access-Control-Allow-Headers' : 'Origin, Content-Type, Accept, X-Custom-Header, Upgrade-Insecure-Requests',
                  })
                };
          
                httpOptionsGet = {
                  headers: new HttpHeaders({
                    'Content-Type': 'application/json',
                    'Access-Control-Allow-Origin': '*',
                  })
                };
          
                _login(username, password) {
                  const url = this.domain + '/api/login?username='+username+'&amp;password='+password;
                  return this.http.post(url, {}, this.httpOptionsPost);
                }
  
  Login Component: 
  
      this.apiService._login(data.username, data.password).subscribe((resp: any) =&gt; {
            const resobj = JSON.parse(JSON.stringify(resp));
            console.log(resobj);
      })
          
          
  </code></pre>
  <p><a href="https://i.stack.imgur.com/9pAfx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9pAfx.jpg" alt="Screenshot to show error" /></a></p>