Personal I'm having a test application in Angular 5 and I'm trying to consume the WebService from the top hat. When making this attempt the following error appears:
Failed to load link : The 'Access-Control-Allow-Origin' header has a value ' a href="https://cartolafc.globo.com"> link 'that is not equal to the supplied origin. Origin ' link ' is therefore not allowed access.
I know that for test questions I can simply disable this validation either via plugin or by another option. But in the case of an actual application. For example, I'm going to create this application and it will consume the WebService of the top hat. How do I fix this?
Service:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Usuario } from '../model/usuario.model';
import { URL_API } from '../util/constantes';
import { Observable } from '../../../node_modules/rxjs';
const httpOptions = {
headers: new HttpHeaders({'Content-Type':'application/json'})
};
@Injectable()
export class UsuarioService {
constructor(private http: HttpClient) { }
public teste2(){
return this.http.get('https://api.cartolafc.globo.com/mercado/status', httpOptions);
}
}
Component:
// O botão no meu HTML chama esse método teste()
public teste(): void{
this.serviceUsuario.teste2()
.subscribe(
(response) => {
console.log("Sucesso");
console.log(response);
},
err => {
console.log("Erro");
console.log(err);
}
)
}