Skip to content

Instantly share code, notes, and snippets.

@saimon24
Created July 15, 2016 16:01
Show Gist options
  • Save saimon24/031a74f9d4d74c6c0347024a542a81a3 to your computer and use it in GitHub Desktop.
Save saimon24/031a74f9d4d74c6c0347024a542a81a3 to your computer and use it in GitHub Desktop.
import { Component } from "@angular/core";
import { Http, HTTP_PROVIDERS } from '@angular/http';
import 'rxjs/add/operator/map';
import {Router} from "@angular/router";
@Component({
selector: "list",
providers: [HTTP_PROVIDERS],
templateUrl: "pages/list/list.component.html"
})
export class ListPage {
pokemon: Array<any> = [];
isLoading = false;
listLoaded = false;
constructor(private router: Router, private http: Http) {}
ngOnInit() {
this.isLoading = true;
this.http.get("http://pokeapi.co/api/v2/pokemon?limit=150")
.map(res => res.json())
.subscribe((data) => {
this.pokemon = data["results"];
},
(err) => {
console.error(err);
alert("Failed to load the data:" + JSON.stringify(err));
},
() => {
this.isLoading = false;
this.listLoaded = true;
})
}
public showDetails(args: any) {
let selectedPokemon = this.pokemon[args.index];
this.router.navigate(["/pokemon", encodeURIComponent(selectedPokemon["url"]) ]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment