I'm using angular 2 to get some data from 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)
);
}
}
If I write console.log(this.gifs) , it logs nothing.
But if I write console.log(gifs) from inside the arrow function, it prints the object I want.
What do I do?