diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 1448314..cb599ee 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -5,6 +5,7 @@ import { AppComponent } from './app.component'; import { SpellsComponent } from './components/spells/spells.component'; import { ClassesComponent } from './components/classes/classes.component'; import { SpellComponent } from './components/spell/spell.component'; +import { MonsterComponent } from './components/monster/monster.component'; const routes: Routes = [ { @@ -16,6 +17,10 @@ const routes: Routes = [ path: 'monsters', component: MonstersComponent, }, + { + path: 'monster/:id', + component: MonsterComponent, + }, { path: 'spells', component: SpellsComponent, diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2ba9c46..5912fba 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -13,6 +13,7 @@ import { NgxDatatableModule } from '@swimlane/ngx-datatable'; import { ClassesComponent } from './components/classes/classes.component'; import {ClassesService} from './services/classes.service'; import { SpellComponent } from './components/spell/spell.component'; +import { MonsterComponent } from './components/monster/monster.component'; @NgModule({ declarations: [ @@ -21,6 +22,7 @@ import { SpellComponent } from './components/spell/spell.component'; SpellsComponent, ClassesComponent, SpellComponent, + MonsterComponent, ], imports: [ BrowserModule, diff --git a/src/app/components/monster/monster.component.css b/src/app/components/monster/monster.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/monster/monster.component.html b/src/app/components/monster/monster.component.html new file mode 100644 index 0000000..a8c2fcf --- /dev/null +++ b/src/app/components/monster/monster.component.html @@ -0,0 +1,24 @@ +
+ +
+

{{ monster.name }}

+

{{ monster.desc }}

+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+ +
diff --git a/src/app/components/monster/monster.component.spec.ts b/src/app/components/monster/monster.component.spec.ts new file mode 100644 index 0000000..0fdea5f --- /dev/null +++ b/src/app/components/monster/monster.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MonsterComponent } from './monster.component'; + +describe('MonsterComponent', () => { + let component: MonsterComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ MonsterComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(MonsterComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/monster/monster.component.ts b/src/app/components/monster/monster.component.ts new file mode 100644 index 0000000..e560735 --- /dev/null +++ b/src/app/components/monster/monster.component.ts @@ -0,0 +1,37 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { Monster } from '../../domain/monsters'; +import { MonstersService } from '../../services/monsters.service'; + +@Component({ + selector: 'app-monster', + templateUrl: './monster.component.html', + styleUrls: ['./monster.component.css'] +}) +export class MonsterComponent implements OnInit { + public monster: Monster + private id: any; + + constructor( + private monsterService: MonstersService, + private router: Router, + private activatedRoute: ActivatedRoute + ) { + + this.activatedRoute.params + .subscribe(params => { + if (params.id) { + this.id = params.id; + } else { + // redirect back to monsters + } + }); + + + } + + ngOnInit() { + this.monsterService.getMonster(this.id).subscribe(monster => { this.monster = monster; }); + } + +} diff --git a/src/app/components/spell/spell.component.ts b/src/app/components/spell/spell.component.ts index 28036b4..355b0ae 100644 --- a/src/app/components/spell/spell.component.ts +++ b/src/app/components/spell/spell.component.ts @@ -17,6 +17,7 @@ export class SpellComponent implements OnInit { private router: Router, private activatedRoute: ActivatedRoute ) { + this.activatedRoute.params .subscribe(params => { if (params.id) { diff --git a/src/app/services/monsters.service.ts b/src/app/services/monsters.service.ts index f089634..3e191a4 100644 --- a/src/app/services/monsters.service.ts +++ b/src/app/services/monsters.service.ts @@ -28,4 +28,10 @@ export class MonstersService implements OnDestroy { return this.http.get(url, this.options); } + public getMonster(id: number) { + const url = this.baseUrl + this.apiEndpoint + '/' + id; + + return this.http.get(url, this.options); + } + }