closes #488 ToH History (oldest-to-latest): ---------------------------- created code example/snippets files for use with +makeExample, replace usage of "pre.prettyprint.lang-bash" with this: code-example(format="." language="bash"). fixed spelling errors in examples file path used by +makeExample changed usage of "code-example" to "+makeExample" adding code example/snippets files used in toh 1 fixed example file paths, replaced "pre.prettyprint.lang-bash" with "code-example. " (docs) toh-pt3 initial state created code examples for display in jade, starting conversion of Google doc and trying +makeExample rendering all text copied from doc to jade, still some styling and formatting to perform completed conversion and styling, moved toh3 example files to "tutorial" folder under _examples created specific code example files for chapter toh 3 and re-pathed references in +makeExample minor edit docs) toh combined - initial combined commit updated ToH for a.52 tons of changes, including de-kebab-ing, removed src folder, updated tsconfig too fixing snippets using incorrect ending input tag using inline html and css for the app.component. ToH Part 1 Code: updated the imports, removed obsolete directive delcarations ToH Code Part 1: updated to use imports, interface. will hit others soon toh part 1: ngModel fix toh part1: removed obsolete story that referred to how we used to have to import and declare all directives we used. yay! ToH Part 1: updated to use `boot.ts` and `app.component.ts`. this affected the partials, snippets, and the story. toh part 1: using `npm run go` toh parts 1 -4: modified all places to use `npm run go` toh part 1: refactor for jade toh part 1: fixing the code samples toh part 2: seeping through the story toh part 2: fixing snippets. toh part 2: replaced ngClass with class.selected toh part 2: removed whitespace toh part 2: added final state to the code toh: fixing paths toh part 4: fixing src/app path to app toh part 3: fixing folder path toh part 2: fixed typo toh part 2: typo on ngModel toh part 2: added ngif toh part 2: removed old hero property. moved the details lower, where we need it toh index: updated hero list image to show consistent styling as the other images here QS spelling error (targes -> targets) tweeks: space and ngIF
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
// #docregion pt2
|
|
import {Component} from 'angular2/core';
|
|
|
|
interface Hero {
|
|
id: number;
|
|
name: string;
|
|
}
|
|
|
|
@Component({
|
|
selector: 'my-app',
|
|
template:`
|
|
<h1>{{title}}</h1>
|
|
<h2>My Heroes</h2>
|
|
<ul class="heroes">
|
|
<li *ngFor="#hero of heroes"
|
|
[class.selected]="hero === selectedHero"
|
|
(click)="onSelect(hero)">
|
|
<span class="badge">{{hero.id}}</span> {{hero.name}}
|
|
</li>
|
|
</ul>
|
|
<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>
|
|
`,
|
|
styles:[`
|
|
.heroes {list-style-type: none; margin-left: 1em; padding: 0; width: 10em;}
|
|
|
|
.heroes li { cursor: pointer; position: relative; left: 0; transition: all 0.2s ease; }
|
|
|
|
.heroes li:hover {color: #369; background-color: #EEE; left: .2em;}
|
|
|
|
.heroes .badge {
|
|
font-size: small;
|
|
color: white;
|
|
padding: 0.1em 0.7em;
|
|
background-color: #369;
|
|
line-height: 1em;
|
|
position: relative;
|
|
left: -1px;
|
|
top: -1px;
|
|
}
|
|
.selected { background-color: #EEE; color: #369; }
|
|
`]
|
|
})
|
|
export class AppComponent {
|
|
public title = 'Tour of Heroes';
|
|
public heroes = HEROES;
|
|
public selectedHero: Hero;
|
|
|
|
onSelect(hero: Hero) { this.selectedHero = hero; }
|
|
}
|
|
// #enddocregion pt2
|
|
|
|
// #docregion hero-array
|
|
var HEROES: Hero[] = [
|
|
{ "id": 11, "name": "Mr. Nice" },
|
|
{ "id": 12, "name": "Narco" },
|
|
{ "id": 13, "name": "Bombasto" },
|
|
{ "id": 14, "name": "Celeritas" },
|
|
{ "id": 15, "name": "Magneta" },
|
|
{ "id": 16, "name": "RubberMan" },
|
|
{ "id": 17, "name": "Dynama" },
|
|
{ "id": 18, "name": "Dr IQ" },
|
|
{ "id": 19, "name": "Magma" },
|
|
{ "id": 20, "name": "Tornado" }
|
|
];
|
|
// #enddocregion hero-array
|
|
|
|
// #enddocregion pt2
|