diff --git a/src/app/my-component/my-component.component.html b/src/app/my-component/my-component.component.html index e3e425b..94499eb 100644 --- a/src/app/my-component/my-component.component.html +++ b/src/app/my-component/my-component.component.html @@ -13,6 +13,8 @@ id : {{id}} {{poke.name}} + +
diff --git a/src/app/my-component/my-component.component.ts b/src/app/my-component/my-component.component.ts index 68c2ff0..086d7fd 100644 --- a/src/app/my-component/my-component.component.ts +++ b/src/app/my-component/my-component.component.ts @@ -2,12 +2,13 @@ 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] + providers: [PokeAPIServiceService] }) export class MyComponentComponent { id: string; @@ -16,7 +17,8 @@ export class MyComponentComponent { pokeDetail : PokeDetail; pokes : Pokemon[] = []; - constructor(private pokeService: PokeAPIServiceService){ + 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")); @@ -42,6 +44,34 @@ export class MyComponentComponent { 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) + + } + + } \ No newline at end of file diff --git a/src/app/poke-apiservice.service.ts b/src/app/poke-apiservice.service.ts index d26f660..220b9ef 100644 --- a/src/app/poke-apiservice.service.ts +++ b/src/app/poke-apiservice.service.ts @@ -1,9 +1,10 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/internal/Observable'; -import { PokeDetail, PokeServiceRes } from './pokemon'; +import { PokeDetail, PokeServiceRes} from './pokemon'; +import { UrlCodec } from '@angular/common/upgrade'; -const url = 'https://pokeapi.co/api/v2/pokemon/'; +const url = 'https://pokeapi.co/api/v2/'; @Injectable({ providedIn: 'root' @@ -15,10 +16,12 @@ export class PokeAPIServiceService { } getPokemons(): Observable{ - return this.http.get(url); + return this.http.get(url + 'pokemon/'); } getPokemonInfo(id:string): Observable{ - return this.http.get(url + id + '/'); + return this.http.get(url + 'pokemon/' + id + '/'); } + + } diff --git a/src/app/poke-share-info.service.spec.ts b/src/app/poke-share-info.service.spec.ts new file mode 100644 index 0000000..eab9fb5 --- /dev/null +++ b/src/app/poke-share-info.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { PokeShareInfoService } from './poke-share-info.service'; + +describe('PokeShareInfoService', () => { + let service: PokeShareInfoService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(PokeShareInfoService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/poke-share-info.service.ts b/src/app/poke-share-info.service.ts new file mode 100644 index 0000000..0e8f40c --- /dev/null +++ b/src/app/poke-share-info.service.ts @@ -0,0 +1,20 @@ +import { Injectable } from '@angular/core'; +import { Subject } from 'rxjs'; + +@Injectable({ + providedIn: 'root' +}) +export class PokeShareInfoService { + + constructor() { } + + public stringVar = new Subject; + + setValue(newStringVar:string){ + this.stringVar.next(newStringVar) + } + + getObservable():Subject{ + return this.stringVar; + } +} diff --git a/src/app/pokedetail/pokedetail.component.html b/src/app/pokedetail/pokedetail.component.html index f1c800d..b229e1b 100644 --- a/src/app/pokedetail/pokedetail.component.html +++ b/src/app/pokedetail/pokedetail.component.html @@ -1,8 +1,38 @@ -
- #{{detail.id}} {{detail.name}} +
+
-
    -
  • {{ability.ability.name}}
  • -
+
+ #{{detail.id}} {{detail.name}} +
+
+
  • {{type.type.name}}
  • +
    +
    +
    +
    +
      +
    • {{ability.ability.name}}
    • +
    +
    +
    + + + + + + + + + + + + + + + + + +
    MaleFemale
    same
    same
    same
    same
    +
    \ No newline at end of file diff --git a/src/app/pokedetail/pokedetail.component.ts b/src/app/pokedetail/pokedetail.component.ts index d60367d..bbd0afa 100644 --- a/src/app/pokedetail/pokedetail.component.ts +++ b/src/app/pokedetail/pokedetail.component.ts @@ -1,13 +1,24 @@ -import { Component, Input} from '@angular/core'; +import { Component, Input, OnInit} from '@angular/core'; import { PokeDetail } from '../pokemon'; +import { PokeShareInfoService } from '../poke-share-info.service'; +import { PokeAPIServiceService } from '../poke-apiservice.service'; @Component({ selector: 'app-pokedetail', templateUrl: './pokedetail.component.html', - styleUrl: './pokedetail.component.css' + styleUrl: './pokedetail.component.css', + providers: [PokeAPIServiceService] }) -export class PokedetailComponent { +export class PokedetailComponent implements OnInit { + + @Input('detail') detail: PokeDetail; + + constructor(private PokeShareInfoService: PokeShareInfoService){ + this.PokeShareInfoService.getObservable().subscribe(e=> console.log('e ' + e)) + } + ngOnInit(): void { + } } diff --git a/src/app/pokemon.ts b/src/app/pokemon.ts index 1fdfdf6..e00b14e 100644 --- a/src/app/pokemon.ts +++ b/src/app/pokemon.ts @@ -192,6 +192,8 @@ export interface Type { } + + export class Pokemon { diff --git a/src/styles.css b/src/styles.css index 320df02..e3fedf0 100644 --- a/src/styles.css +++ b/src/styles.css @@ -14,13 +14,30 @@ div.filter_pokedex{ div.pokemon{ display: inline-block; align-items: center; + margin: 15px } div.pokemonTitle{ display: inline-block; font-size: 30px; + vertical-align: top; } div.pokemonDetail{ display: inline-block; -} \ No newline at end of file + vertical-align: top; +} + +div.pokemonSprite{ + image-rendering: pixelated; + display: inline-block; + vertical-align: top; +} + +img{ + image-rendering: pixelated; +} + +table.sprites{ + border-collapse: collapse; +}