I'm trying to fetch records that are in an API on the heroku server with the following URL https://mdw-arm-wladimir.herokuapp.com/noticias
But when I receive this url in my Angular project it generates this error;
This is my Angular service class
import { Noticia } from './../core/model';
import { Injectable } from '@angular/core';
import { Http, Headers, URLSearchParams } from '@angular/http';
import 'rxjs/add/operator/toPromise';
import * as moment from 'moment';
export class NoticiaFiltro {
titulo: string;
font: string;
pagina = 0;
itensPorPagina = 8;
}
@Injectable()
export class NoticiaService {
noticiasUrl = 'https://mdw-arm-wladimir.herokuapp.com/noticias';
constructor(private http: Http) { }
pesquisar(filtro: NoticiaFiltro): Promise<any> {
const params = new URLSearchParams();
const headers = new Headers();
params.set('page', filtro.pagina.toString());
params.set('size', filtro.itensPorPagina.toString());
if (filtro.titulo) {
params.set('titulo', filtro.titulo);
}
if (filtro.font) {
params.set('font', filtro.font);
}
return this.http.get('${this.noticiasUrl}', { headers, search: params })
.toPromise()
.then(response => {
const responseJson = response.json();
const noticias = responseJson.content;
const resultado = {
noticias,
total: responseJson.totalElements
};
return resultado;
});
}
adicionar(noticia: Noticia): Promise<Noticia> {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(this.noticiasUrl,
JSON.stringify(noticia), { headers })
.toPromise()
.then(response => response.json());
}
excluir(codigo: number): Promise<void> {
const headers = new Headers();
return this.http.delete('${this.noticiasUrl}/${codigo}', { headers })
.toPromise()
.then(() => null);
}
atualizar(noticia: Noticia): Promise<Noticia> {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.put('${this.noticiasUrl}/${noticia.codigo}',
JSON.stringify(noticia), { headers })
.toPromise()
.then(response => {
const lancamentoAlterado = response.json() as Noticia;
this.converterStringsParaDatas([lancamentoAlterado]);
return lancamentoAlterado;
});
}
buscarPorCodigo(codigo: number): Promise<Noticia> {
const headers = new Headers();
return this.http.get('${this.noticiasUrl}/${codigo}', { headers })
.toPromise()
.then(response => {
const noticia = response.json() as Noticia;
this.converterStringsParaDatas([noticia]);
return noticia;
});
}
private converterStringsParaDatas(noticias: Noticia[]) {
for (const noticia of noticias) {
noticia.dataNoticia = moment(noticia.dataNoticia,
'YYYY-MM-DD').toDate();
}
}
}
Would anyone know how to help me solve this problem?