Utilizing Angular 2 to fetch data from the GIPHY API.
export class ListaGifsComponent {
gifs : Object[] = [];
urlBase = "http://api.giphy.com/v1/gifs/search?q=";
termoPesquisado = "ryan+gosling";
key = "O8RhkTXfiSPmSCHosPAnhO70pdnHUiWn";
constructor(http: Http){
http
.get(this.urlBase + this.termoPesquisado +
"&api_key=" + this.key + "&limit=10")
.map(res => res.json())
.subscribe(gifs =>
this.gifs = gifs['data'],
erro => console.log(erro)
);
}
}
When I use console.log(this.gifs), nothing is logged.
However, if I use console.log(gifs) within the arrow function, it displays the desired object.
How can I resolve this issue?