3: Create a Feature Component
authorKai Moritz <kai@juplo.de>
Sat, 2 May 2020 17:11:56 +0000 (19:11 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 2 May 2020 17:22:56 +0000 (19:22 +0200)
a) Make the HeroDetailComponent

src/app/app.module.ts
src/app/hero-detail/hero-detail.component.css [new file with mode: 0644]
src/app/hero-detail/hero-detail.component.html [new file with mode: 0644]
src/app/hero-detail/hero-detail.component.spec.ts [new file with mode: 0644]
src/app/hero-detail/hero-detail.component.ts [new file with mode: 0644]
src/app/heroes/heroes.component.html

index bc5d602..39fe27d 100644 (file)
@@ -4,11 +4,13 @@ import { FormsModule } from '@angular/forms';
 
 import { AppComponent } from './app.component';
 import { HeroesComponent } from './heroes/heroes.component';
+import { HeroDetailComponent } from './hero-detail/hero-detail.component';
 
 @NgModule({
   declarations: [
     AppComponent,
-    HeroesComponent
+    HeroesComponent,
+    HeroDetailComponent
   ],
   imports: [
     BrowserModule,
diff --git a/src/app/hero-detail/hero-detail.component.css b/src/app/hero-detail/hero-detail.component.css
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/app/hero-detail/hero-detail.component.html b/src/app/hero-detail/hero-detail.component.html
new file mode 100644 (file)
index 0000000..fa00c62
--- /dev/null
@@ -0,0 +1,8 @@
+<div *ngIf="hero">
+  <h2>{{hero.name | uppercase}} Details</h2>
+  <div><span>id: </span>{{hero.id}}</div>
+  <div>
+    <label>name: </label>
+    <input [(ngModel)]="hero.name" placeholder="Type a name..." />
+  </div>
+</div>
diff --git a/src/app/hero-detail/hero-detail.component.spec.ts b/src/app/hero-detail/hero-detail.component.spec.ts
new file mode 100644 (file)
index 0000000..5e34497
--- /dev/null
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { HeroDetailComponent } from './hero-detail.component';
+
+describe('HeroDetailComponent', () => {
+  let component: HeroDetailComponent;
+  let fixture: ComponentFixture<HeroDetailComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      declarations: [ HeroDetailComponent ]
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(HeroDetailComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});
diff --git a/src/app/hero-detail/hero-detail.component.ts b/src/app/hero-detail/hero-detail.component.ts
new file mode 100644 (file)
index 0000000..caa9c09
--- /dev/null
@@ -0,0 +1,18 @@
+import { Component, OnInit, Input } from '@angular/core';
+import { Hero } from '../hero';
+
+@Component({
+  selector: 'app-hero-detail',
+  templateUrl: './hero-detail.component.html',
+  styleUrls: ['./hero-detail.component.css']
+})
+export class HeroDetailComponent implements OnInit {
+
+  @Input() hero : Hero;
+
+  constructor() { }
+
+  ngOnInit() {
+  }
+
+}
index cd87f96..e0067e7 100644 (file)
@@ -4,11 +4,3 @@
     <span class="badge">{{hero.id}}</span> {{hero.name}}
   </li>
 </ul>
-<div *ngIf="selectedHero">
-  <h2>{{selectedHero.name | uppercase}} Details</h2>
-  <div><span>id: </span>{{selectedHero.id}}</div>
-  <div>
-    <label>name: </label>
-    <input [(ngModel)]="selectedHero.name" placeholder="Type a name..." />
-  </div>
-</div>