import { Component } from '@angular/core'; //import { constructor } from 'jasmine'; import { PokeDetail, Pokemon } from '../pokemon'; import { PokeAPIServiceService } from '../poke-apiservice.service'; import { PokeShareInfoService } from '../poke-share-info.service'; @Component({ selector: 'app-my-component', templateUrl: './my-component.component.html', styleUrl: './my-component.component.css', providers: [PokeAPIServiceService] }) export class MyComponentComponent { id: string; selectedPokeId : string; searchPokeName: string; pokeDetail : PokeDetail; pokes : Pokemon[] = []; constructor(private pokeService: PokeAPIServiceService, private PokeShareInfoService: PokeShareInfoService){ /*this.pokes.push(new Pokemon('1', "Bulbizarre")); this.pokes.push(new Pokemon('2', "Herbizarre")); this.pokes.push(new Pokemon('3', "Florizarre")); this.pokes.push(new Pokemon('4', "Salamèche")); this.pokes.push(new Pokemon('5', "Reptincel")); this.pokes.push(new Pokemon('6', "Dracaufeu")); this.pokes.push(new Pokemon('7', "Carapute")); this.pokes.push(new Pokemon('8', "Carabaffe")); this.pokes.push(new Pokemon('9', "Tortank"));*/ } ngOnInit(): void { this.pokeService.getPokemons().subscribe((data)=>{ data.results.forEach((e,index) =>{ this.pokes.push(new Pokemon((index+1)+'', e.name)); }) } ); }; go(){ this.id=this.selectedPokeId; if (this.selectedPokeId != ''){ this.pokeService.getPokemonInfo(this.selectedPokeId).subscribe(data=> this.pokeDetail = data) //this.PokeShareInfoService.setValue(this.selectedPokeId); } } previous_pokemon(){ var n_id: number = +this.id if(n_id>1){ this.id = n_id-1+"" } else{ this.id = ""+this.pokes.length } this.selectedPokeId = this.id this.pokeService.getPokemonInfo(this.selectedPokeId).subscribe(data=> this.pokeDetail = data) } next_pokemon(){ var n_id: number = +this.id if(n_id this.pokeDetail = data) } }