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