I try to pick up the JSON provided by an API that I have created in a service, but I do not receive it for whatever reason.
getLibro(id: string){
return this._http.get(this.url + 'libros/' + id)
.map(res => {
console.log(res.json()); //No muestra nada
return res.json();
})
However, the getLibros () method does not have problems when collecting the information. Next, the entire service:
import { Injectable } from '@angular/core';
import { Http } from "@angular/http";
import 'rxjs/add/operator/map';
import { Observable } from "rxjs/Observable";
@Injectable()
export class LibrosService {
url: string = "http://localhost/API/public/index.php/api/";
constructor(private _http: Http) { }
getLibros(){
return this._http.get(this.url + 'libros')
.map(res => res.json()); //recoge el json perfectamene
}
getLibro(id: string){
return this._http.get(this.url + 'libros/' + id)
.map(res => {
console.log(res.json()); //No muestra nada
return res.json();
})
}
I appreciate the help in advance.