Skip to content

Instantly share code, notes, and snippets.

export class AppComponent{
pokemon
constructor(private pokedexService: PokedexService) {}
ngOnInit(){}
}
getPokemon(index:number){
return this.http.get(`${this.baseUrl}${index}`)
.subscribe(
res => {return res.json().results}
);
}
@Injectable()
export class PokedexService {
private baseUrl: string ='https://pokeapi.co/api/v2/';
constructor(private http: Http) { }
getPokemon(index:number) {
return this.http.get(`${this.baseUrl}pokemon/${index}`)
}
}
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';