|
| 1 | +//#docregion |
| 2 | +import 'package:angular2/core.dart'; |
| 3 | + |
| 4 | +// #docregion hero-import |
| 5 | +import 'hero.dart'; |
| 6 | +// #enddocregion hero-import |
| 7 | +// #docregion hero-detail-import |
| 8 | +import 'hero_detail_component.dart'; |
| 9 | +// #enddocregion hero-detail-import |
| 10 | + |
| 11 | +@Component( |
| 12 | + selector: 'my-app', |
| 13 | +// #docregion hero-detail-template |
| 14 | + template: ''' |
| 15 | + <h1>{{title}}</h1> |
| 16 | + <h2>My Heroes</h2> |
| 17 | + <ul class="heroes"> |
| 18 | + <li *ngFor="#hero of heroes" |
| 19 | + [class.selected]="hero == selectedHero" |
| 20 | + (click)="onSelect(hero)"> |
| 21 | + <span class="badge">{{hero.id}}</span> {{hero.name}} |
| 22 | + </li> |
| 23 | + </ul> |
| 24 | + <my-hero-detail [hero]="selectedHero"></my-hero-detail> |
| 25 | + ''', |
| 26 | +// #enddocregion hero-detail-template |
| 27 | + styles: const [''' |
| 28 | + .selected { |
| 29 | + background-color: #CFD8DC !important; |
| 30 | + color: white; |
| 31 | + } |
| 32 | + .heroes { |
| 33 | + margin: 0 0 2em 0; |
| 34 | + list-style-type: none; |
| 35 | + padding: 0; |
| 36 | + width: 10em; |
| 37 | + } |
| 38 | + .heroes li { |
| 39 | + cursor: pointer; |
| 40 | + position: relative; |
| 41 | + left: 0; |
| 42 | + background-color: #EEE; |
| 43 | + margin: .5em; |
| 44 | + padding: .3em 0em; |
| 45 | + height: 1.6em; |
| 46 | + border-radius: 4px; |
| 47 | + } |
| 48 | + .heroes li.selected:hover { |
| 49 | + color: white; |
| 50 | + } |
| 51 | + .heroes li:hover { |
| 52 | + color: #607D8B; |
| 53 | + background-color: #EEE; |
| 54 | + left: .1em; |
| 55 | + } |
| 56 | + .heroes .text { |
| 57 | + position: relative; |
| 58 | + top: -3px; |
| 59 | + } |
| 60 | + .heroes .badge { |
| 61 | + display: inline-block; |
| 62 | + font-size: small; |
| 63 | + color: white; |
| 64 | + padding: 0.8em 0.7em 0em 0.7em; |
| 65 | + background-color: #607D8B; |
| 66 | + line-height: 1em; |
| 67 | + position: relative; |
| 68 | + left: -1px; |
| 69 | + top: -4px; |
| 70 | + height: 1.8em; |
| 71 | + margin-right: .8em; |
| 72 | + border-radius: 4px 0px 0px 4px; |
| 73 | + } |
| 74 | + ''' |
| 75 | + ], |
| 76 | +// #docregion directives |
| 77 | + directives: const [ |
| 78 | + HeroDetailComponent |
| 79 | + ]) |
| 80 | +// #enddocregion directives |
| 81 | +class AppComponent { |
| 82 | + final String title = 'Tour of Heroes'; |
| 83 | + final List<Hero> heroes = mockHeroes; |
| 84 | + Hero selectedHero; |
| 85 | + |
| 86 | + onSelect(Hero hero) { |
| 87 | + selectedHero = hero; |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +final List<Hero> mockHeroes = [ |
| 92 | + new Hero(11, "Mr. Nice"), |
| 93 | + new Hero(12, "Narco"), |
| 94 | + new Hero(13, "Bombasto"), |
| 95 | + new Hero(14, "Celeritas"), |
| 96 | + new Hero(15, "Magneta"), |
| 97 | + new Hero(16, "RubberMan"), |
| 98 | + new Hero(17, "Dynama"), |
| 99 | + new Hero(18, "Dr IQ"), |
| 100 | + new Hero(19, "Magma"), |
| 101 | + new Hero(20, "Tornado") |
| 102 | +]; |
0 commit comments