Angular getting CORS No Access-Control-Allow Origin when references css file on a https server [duplicate]

1

I have an inconvenient create a rest api in Java

Where I want to consume it in angular

import { Injectable } from '@angular/core';
import { Http,Headers } from '@angular/http';


import { Observable, Subject } from 'rxjs';
import 'rxjs/add/operator/map'; 
import 'rxjs/add/operator/catch';

@Injectable({
  providedIn: 'root'
})
export class SpotifyService {

  constructor(private http: Http) {
    console.log('Spotify Service Listo');
    
  }




   getAlbumHome(){

       
       return this.http.get('http://localhost:2019/ServiciosWeb13/rest/servicioAlbum/listarAlbunes').
       map(res=>{
           return res.json();
       });
       
     }
       
   /*
   getAlbumSearch(termino: string){
       return this.getQuery('buscarByAlbum?nombre=${termino}')
       .map(res=>res.json());
   }
  getObtenerArtista(id:String){
       return this.getQuery('obtenerMusica?id=${id}')
       .map(res=>res.json());
   }
   getObtenerMusica(id:String){
       return this.getQuery('obtenerMusica?id=${id}')
       .map(res=>res.json());
   }*/
}

But when executing my Angular project I get this error, I do not know how to solve it

    
asked by Chris Alexis 30.11.2018 в 04:26
source

1 answer

0

It's because of the new browser policy. You need to configure your web server for CORS.

link

In the header (header) of your rest api response you will need to add something like this:

header('Access-Control-Allow-Origin: *');
    
answered by 30.11.2018 в 10:49