Created
July 15, 2016 16:01
-
-
Save saimon24/031a74f9d4d74c6c0347024a542a81a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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