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,
--- /dev/null
+<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>
--- /dev/null
+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();
+ });
+});
--- /dev/null
+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() {
+ }
+
+}
<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>