Skip to content

Instantly share code, notes, and snippets.

@jhades
Last active May 12, 2016 07:45
Show Gist options
  • Save jhades/30c0ffde33b402e9b3aacf8ad61bc2ae to your computer and use it in GitHub Desktop.
Save jhades/30c0ffde33b402e9b3aacf8ad61bc2ae to your computer and use it in GitHub Desktop.
@Component({
selector: 'app',
directives: [Hero, Heroes],
template: `
<heroes>
<hero id="1" name="Superman"></hero>
<hero id="2" name="Batman"></hero>
<hero id="3" name="Batgirl"></hero>
<hero id="3" name="Robin"></hero>
<hero id="4" name="Flash"></hero>
<hero id="5" name="Green Lantern"></hero>
</heroes>
`
})
export class App {
}
bootstrap(App);
@Directive({
selector: 'hero',
})
export class Hero {
@Input()
id: number;
@Input()
name:string;
}
const HEROES = [
{id: 1, name:'Superman'},
{id: 2, name:'Batman'},
{id: 5, name:'BatGirl'},
{id: 3, name:'Robin'},
{id: 4, name:'Flash'}
];
@Component({
selector:'heroes',
template: `
<table>
<thead>
<th>Name</th>
<th>Index</th>
</thead>
<tbody>
<tr *ngFor="let hero of heroes; let i = index">
<td>{{hero.name}}</td>
<td>{{i}}</td>
</tr>
</tbody>
</table>
`
})
export class Heroes {
@ContentChildren(Hero)
heroes: QueryList<Hero>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment