('updateHero'))
+ );
}
}
diff --git a/src/app/heroes/heroes.component.css b/src/app/heroes/heroes.component.css
index 2ad3fef..6d1344b 100644
--- a/src/app/heroes/heroes.component.css
+++ b/src/app/heroes/heroes.component.css
@@ -49,3 +49,25 @@
margin-right: .8em;
border-radius: 4px 0 0 4px;
}
+
+button {
+ background-color: #eee;
+ border: none;
+ padding: 5px 10px;
+ border-radius: 4px;
+ cursor: pointer;
+ cursor: hand;
+ font-family: Arial;
+}
+
+button:hover {
+ background-color: #cfd8dc;
+}
+
+button.delete {
+ position: relative;
+ left: 194px;
+ top: -32px;
+ background-color: gray !important;
+ color: white;
+}
diff --git a/src/app/heroes/heroes.component.html b/src/app/heroes/heroes.component.html
index 2eb180e..efbaa1e 100644
--- a/src/app/heroes/heroes.component.html
+++ b/src/app/heroes/heroes.component.html
@@ -1,8 +1,19 @@
My Heroes
+
+
+
+
+
diff --git a/src/app/heroes/heroes.component.ts b/src/app/heroes/heroes.component.ts
index c33d11d..8994ada 100644
--- a/src/app/heroes/heroes.component.ts
+++ b/src/app/heroes/heroes.component.ts
@@ -22,4 +22,18 @@ export class HeroesComponent implements OnInit {
this.heroService.getHeroes()
.subscribe(heroes => this.heroes = heroes);
}
+
+ add(name: string): void {
+ name = name.trim();
+ if (!name) { return; }
+ this.heroService.addHero({ name } as Hero)
+ .subscribe(hero => {
+ this.heroes.push(hero);
+ });
+ }
+
+ delete(hero: Hero): void {
+ this.heroes = this.heroes.filter(h => h !== hero);
+ this.heroService.deleteHero(hero).subscribe();
+ }
}
diff --git a/src/app/in-memory-data.service.ts b/src/app/in-memory-data.service.ts
new file mode 100644
index 0000000..455ce42
--- /dev/null
+++ b/src/app/in-memory-data.service.ts
@@ -0,0 +1,32 @@
+import { Injectable } from '@angular/core';
+import {InMemoryDbService} from "angular-in-memory-web-api";
+import {Observable} from "rxjs";
+import {Hero} from "./hero";
+
+@Injectable({
+ providedIn: 'root'
+})
+export class InMemoryDataService implements InMemoryDbService {
+
+ constructor() { }
+
+ createDb() {
+ const heroes = [
+ { id: 11, name: 'Dr Nice' },
+ { id: 12, name: 'Narco' },
+ { id: 13, name: 'Bombasto' },
+ { id: 14, name: 'Celeritas' },
+ { id: 15, name: 'Magneta' },
+ { id: 16, name: 'RubberMan' },
+ { id: 17, name: 'Dynama' },
+ { id: 18, name: 'Dr IQ' },
+ { id: 19, name: 'Magma' },
+ { id: 20, name: 'Tornado' }
+ ];
+ return {heroes};
+ }
+
+ genId(heroes: Hero[]): number {
+ return heroes.length > 0 ? Math.max(...heroes.map(hero => hero.id)) + 1 : 11;
+ }
+}