I am trying to call an API within Angular that requires authorization. My code compiles, but the data does not display, and in the developer tools I get an error message saying that my access has been blocked by CORS policy and there's no access-control-allow-origin. I have been using a CORS Chrome extension to enable CORS. I've provided the code I've been using below, I'm very new to Angular so it's very simple, but I didn't know if there was a way to fix this and get the API call to work? I also do not have access to the server side code, so I cannot add any CORS code on that side.
app.component.ts
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'My Title';
data: any = {};
constructor(private http: HttpClient) {}
ngOnInit() {
const httpOptions = {
headers: new HttpHeaders({
'Authorization': 'Bearer my-auth-token'
}),
};
this.http.get('https://mygateway.com', httpOptions).subscribe((data)=>{
console.log(data)
});
}
Any help would be appreciated :)