Last active
May 12, 2016 07:45
-
-
Save jhades/30c0ffde33b402e9b3aacf8ad61bc2ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Directive({ | |
selector: 'hero', | |
}) | |
export class Hero { | |
@Input() | |
id: number; | |
@Input() | |
name:string; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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