Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
muyuqiu001 committed Feb 12, 2017
1 parent a58dd5f commit e0c2548
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
15 changes: 2 additions & 13 deletions app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,15 @@ const HEROES: Hero[] = [
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<div *ngIf="selectedHero">
<h2>{{selectedHero.name}} details!</h2>
<div><label>id: </label>{{selectedHero.id}}</div>
<div>
<label>name: </label>
<input [(ngModel)]="selectedHero.name" placeholder="name"/>
</div>
</div>
<h2>My Heroes</h2>
<ul class="heroes">
<li *ngFor="let hero of heroes"
[class.selected]="hero === selectedHero"
(click)="onSelect(hero)">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</li>
</ul>
<my-hero-detail [hero]="selectedHero"></my-hero-detail>
`,
styles: [`
.selected {
Expand Down Expand Up @@ -90,10 +83,6 @@ const HEROES: Hero[] = [
})
export class AppComponent {
title = 'Tour of Heroes';
// hero: Hero = {
// id: 1,
// name: 'Windstorm'
// };
heroes = HEROES;
selectedHero: Hero;

Expand Down
3 changes: 2 additions & 1 deletion app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';

import { HeroDetailComponent } from './hero-detail.component';
import { AppComponent } from './app.component';

@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [AppComponent],
declarations: [AppComponent, HeroDetailComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
20 changes: 20 additions & 0 deletions app/hero-detail.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component, Input } from '@angular/core';
import { Hero } from './hero'

@Component({
selector: 'my-hero-detail',
template: `
<div *ngIf="hero">
<h2>{{hero.name}} details!</h2>
<div><label>id: </label>{{hero.id}}</div>
<div>
<label>name: </label>
<input [(ngModel)]="hero.name" placeholder="name"/>
</div>
</div>
`
})
export class HeroDetailComponent {
@Input()
hero: Hero;
}
4 changes: 4 additions & 0 deletions app/hero.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class Hero {
id: number;
name: string;
}

0 comments on commit e0c2548

Please sign in to comment.