Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit a8ad96e

Browse files
chalinwardbell
authored andcommitted
docs(template-syntax): code fixes and copyedits (#3365)
- onSave "no propagation" case _was_ propagating. Fixed. - `firstName` --> `name` (a few were missed during a previous edit). - Hercules had a _rate_ of 325, not an id; fixed so it matches figure. - Missing closing `</div>` in form HTML - Prose: fix json representation of Hercules (since Hero class has changed). - Added missing AppComponent properties used in template but not declared in class; which will likely result in errors when compiled with AOT. - Some "back to top" were not formatted properly after a figure. - Copyedits, e.g., Angular modules such the --> such as the - Removed Jade blocks no longer used by Dart.
1 parent 0331083 commit a8ad96e

File tree

6 files changed

+403
-251
lines changed

6 files changed

+403
-251
lines changed

public/docs/_examples/template-syntax/ts/src/app/app.component.html

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ <h3>
158158

159159
<div>
160160
<!-- #docregion property-binding-syntax-1 -->
161-
<img [src] = "heroImageUrl">
161+
<img [src]="heroImageUrl">
162162
<hero-detail [hero]="currentHero"></hero-detail>
163-
<div [ngClass] = "{selected: isSelected}"></div>
163+
<div [ngClass]="{special: isSpecial}"></div>
164164
<!-- #enddocregion property-binding-syntax-1 -->
165165
</div>
166166
<br><br>
167167

168168
<!-- #docregion event-binding-syntax-1 -->
169-
<button (click) = "onSave()">Save</button>
169+
<button (click)="onSave()">Save</button>
170170
<hero-detail (deleteRequest)="deleteHero()"></hero-detail>
171171
<div (myClick)="clicked=$event" clickable>click me</div>
172172
<!-- #enddocregion event-binding-syntax-1 -->
@@ -176,9 +176,9 @@ <h3>
176176
<div>
177177
Hero Name:
178178
<!-- #docregion 2-way-binding-syntax-1 -->
179-
<input [(ngModel)]="heroName">
179+
<input [(ngModel)]="name">
180180
<!-- #enddocregion 2-way-binding-syntax-1 -->
181-
{{heroName}}
181+
{{name}}
182182
</div>
183183
<br><br>
184184

@@ -193,7 +193,7 @@ <h3>
193193
<br><br>
194194

195195
<!-- #docregion style-binding-syntax-1 -->
196-
<button [style.color] = "isSpecial ? 'red' : 'green'">
196+
<button [style.color]="isSpecial ? 'red' : 'green'">
197197
<!-- #enddocregion style-binding-syntax-1 -->
198198
button</button>
199199

@@ -349,7 +349,7 @@ <h3>
349349
<hr><h2 id="style-binding">Style Binding</h2>
350350

351351
<!-- #docregion style-binding-1 -->
352-
<button [style.color] = "isSpecial ? 'red': 'green'">Red</button>
352+
<button [style.color]="isSpecial ? 'red': 'green'">Red</button>
353353
<button [style.background-color]="canSave ? 'cyan': 'grey'" >Save</button>
354354
<!-- #enddocregion style-binding-1 -->
355355

@@ -402,14 +402,14 @@ <h3>
402402
<!-- #docregion event-binding-no-propagation -->
403403
<!-- Will save only once -->
404404
<div (click)="onSave()" clickable>
405-
<button (click)="onSave()">Save, no propagation</button>
405+
<button (click)="onSave($event)">Save, no propagation</button>
406406
</div>
407407
<!-- #enddocregion event-binding-no-propagation -->
408408

409409
<!-- #docregion event-binding-propagation -->
410410
<!-- Will save twice -->
411411
<div (click)="onSave()" clickable>
412-
<button (click)="onSave() || true">Save w/ propagation</button>
412+
<button (click)="onSave()">Save w/ propagation</button>
413413
</div>
414414
<!-- #enddocregion event-binding-propagation -->
415415

@@ -460,21 +460,21 @@ <h3>Result: {{currentHero.name}}</h3>
460460
[ngModel]="currentHero.name"
461461
(ngModelChange)="currentHero.name=$event">
462462
<!-- #enddocregion NgModel-3 -->
463-
(ngModelChange) = "...name=$event"
463+
(ngModelChange)="...name=$event"
464464
<br>
465465
<!-- #docregion NgModel-4 -->
466466
<input
467467
[ngModel]="currentHero.name"
468468
(ngModelChange)="setUppercaseName($event)">
469469
<!-- #enddocregion NgModel-4 -->
470-
(ngModelChange) = "setUppercaseName($event)"
470+
(ngModelChange)="setUppercaseName($event)"
471471

472472
<a class="to-toc" href="#toc">top</a>
473473

474474
<!-- NgClass binding -->
475475
<hr><h2 id="ngClass">NgClass Binding</h2>
476476

477-
<p>currentClasses returns {{currentClasses | json}}</p>
477+
<p>currentClasses is {{currentClasses | json}}</p>
478478
<!-- #docregion NgClass-1 -->
479479
<div [ngClass]="currentClasses">This div is initially saveable, unchanged, and special</div>
480480
<!-- #enddocregion NgClass-1 -->
@@ -489,7 +489,7 @@ <h3>Result: {{currentHero.name}}</h3>
489489
<div [ngClass]="currentClasses">
490490
This div should be {{ canSave ? "": "not"}} saveable,
491491
{{ isUnchanged ? "unchanged" : "modified" }} and,
492-
{{ isSpecial ? "": "not"}} special after clicking "refresh".</div>
492+
{{ isSpecial ? "": "not"}} special after clicking "Refresh".</div>
493493
<br><br>
494494

495495
<div [ngClass]="isSpecial ? 'special' : ''">This div is special</div>
@@ -504,12 +504,12 @@ <h3>Result: {{currentHero.name}}</h3>
504504

505505
<!-- #docregion NgStyle-1 -->
506506
<div [style.font-size]="isSpecial ? 'x-large' : 'smaller'" >
507-
This div is x-large.
507+
This div is x-large or smaller.
508508
</div>
509509
<!-- #enddocregion NgStyle-1 -->
510510

511-
<h3>[ngStyle] binding to `currentStyles` - CSS property names</h3>
512-
<p>currentStyles returns {{currentStyles | json}}</p>
511+
<h3>[ngStyle] binding to currentStyles - CSS property names</h3>
512+
<p>currentStyles is {{currentStyles | json}}</p>
513513
<!-- #docregion NgStyle-2 -->
514514
<div [ngStyle]="currentStyles">
515515
This div is initially italic, normal weight, and extra large (24px).
@@ -526,7 +526,7 @@ <h3>[ngStyle] binding to `currentStyles` - CSS property names</h3>
526526
<div [ngStyle]="currentStyles">
527527
This div should be {{ canSave ? "italic": "plain"}},
528528
{{ isUnchanged ? "normal weight" : "bold" }} and,
529-
{{ isSpecial ? "extra large": "normal size"}} after clicking "refresh".</div>
529+
{{ isSpecial ? "extra large": "normal size"}} after clicking "Refresh".</div>
530530

531531
<a class="to-toc" href="#toc">top</a>
532532

@@ -655,14 +655,12 @@ <h4 id="ngFor-trackBy">*ngFor trackBy</h4>
655655
<!-- NgSwitch binding -->
656656
<hr><h2 id="ngSwitch">NgSwitch Binding</h2>
657657

658-
<div>Pick your favorite hero</div>
659-
<p>
660-
<ng-container *ngFor="let h of heroes">
661-
<label>
662-
<input type="radio" name="heroes" [(ngModel)]="currentHero" [value]="h">{{h.name}}
663-
</label>
664-
</ng-container>
665-
</p>
658+
<p>Pick your favorite hero</p>
659+
<div>
660+
<label *ngFor="let h of heroes">
661+
<input type="radio" name="heroes" [(ngModel)]="currentHero" [value]="h">{{h.name}}
662+
</label>
663+
</div>
666664

667665
<!-- #docregion NgSwitch -->
668666
<div [ngSwitch]="currentHero.emotion">

public/docs/_examples/template-syntax/ts/src/app/app.component.ts

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export class AppComponent implements AfterViewInit, OnInit {
3131

3232
ngAfterViewInit() {
3333
// Detect effects of NgForTrackBy
34-
trackChanges(this.heroesNoTrackBy, () => this.heroesNoTrackByCount += 1);
35-
trackChanges(this.heroesWithTrackBy, () => this.heroesWithTrackByCount += 1);
34+
trackChanges(this.heroesNoTrackBy, () => this.heroesNoTrackByCount++);
35+
trackChanges(this.heroesWithTrackBy, () => this.heroesWithTrackByCount++);
3636
}
3737

3838
@ViewChildren('noTrackBy') heroesNoTrackBy: QueryList<ElementRef>;
@@ -42,6 +42,7 @@ export class AppComponent implements AfterViewInit, OnInit {
4242
alert = alerter;
4343
badCurly = 'bad curly';
4444
classes = 'special';
45+
help = '';
4546

4647
callFax(value: string) {this.alert(`Faxing ${value} ...`); }
4748
callPhone(value: string) {this.alert(`Calling ${value} ...`); }
@@ -83,17 +84,9 @@ export class AppComponent implements AfterViewInit, OnInit {
8384

8485
title = 'Template Syntax';
8586

86-
getStyles(el: Element) {
87-
let styles = window.getComputedStyle(el);
88-
let showStyles = {};
89-
for (let p in this.currentStyles) { // only interested in these styles
90-
showStyles[p] = styles[p];
91-
}
92-
return JSON.stringify(showStyles);
93-
}
94-
95-
getVal() { return this.val; }
87+
getVal(): number { return 2; }
9688

89+
name: string = Hero.heroes[0].name;
9790
hero: Hero; // defined to demonstrate template context precedence
9891
heroes: Hero[];
9992

@@ -107,18 +100,16 @@ export class AppComponent implements AfterViewInit, OnInit {
107100
// heroImageUrl = 'http://www.wpclipart.com/cartoon/people/hero/hero_silhoutte_T.png';
108101
// Public Domain terms of use: http://www.wpclipart.com/terms.html
109102
heroImageUrl = 'images/hero.png';
103+
// villainImageUrl = 'http://www.clker.com/cliparts/u/s/y/L/x/9/villain-man-hi.png'
104+
// Public Domain terms of use http://www.clker.com/disclaimer.html
105+
villainImageUrl = 'images/villain.png';
110106

111107
iconUrl = 'images/ng-logo.png';
112108
isActive = false;
113109
isSpecial = true;
114110
isUnchanged = true;
115111

116-
nullHero: Hero = null;
117-
118-
onCancel(event: KeyboardEvent) {
119-
let evtMsg = event ? ' Event target is ' + (<HTMLElement>event.target).innerHTML : '';
120-
this.alert('Canceled.' + evtMsg);
121-
}
112+
get nullHero(): Hero { return null; }
122113

123114
onClickMe(event: KeyboardEvent) {
124115
let evtMsg = event ? ' Event target class is ' + (<HTMLElement>event.target).className : '';
@@ -128,9 +119,10 @@ export class AppComponent implements AfterViewInit, OnInit {
128119
onSave(event: KeyboardEvent) {
129120
let evtMsg = event ? ' Event target is ' + (<HTMLElement>event.target).innerText : '';
130121
this.alert('Saved.' + evtMsg);
122+
if (event) { event.stopPropagation(); }
131123
}
132124

133-
onSubmit() { /* referenced but not used */}
125+
onSubmit() {/* referenced but not used */}
134126

135127
product = {
136128
name: 'frimfram',
@@ -144,17 +136,6 @@ export class AppComponent implements AfterViewInit, OnInit {
144136
this.heroesWithTrackByCountReset = 0;
145137
}
146138

147-
private samenessCount = 5;
148-
moreOfTheSame() { this.samenessCount++; };
149-
get sameAsItEverWas() {
150-
let result: string[] = Array(this.samenessCount);
151-
for ( let i = result.length; i-- > 0; ) { result[i] = 'same as it ever was ...'; }
152-
return result;
153-
// return [1,2,3,4,5].map(id => {
154-
// return {id:id, text: 'same as it ever was ...'};
155-
// });
156-
}
157-
158139
setUppercaseName(name: string) {
159140
this.currentHero.name = name.toUpperCase();
160141
}
@@ -174,8 +155,8 @@ export class AppComponent implements AfterViewInit, OnInit {
174155
// #docregion setStyles
175156
currentStyles: {};
176157
setCurrentStyles() {
158+
// CSS styles: set per current state of component properties
177159
this.currentStyles = {
178-
// CSS styles: set per current state of component properties
179160
'font-style': this.canSave ? 'italic' : 'normal',
180161
'font-weight': !this.isUnchanged ? 'bold' : 'normal',
181162
'font-size': this.isSpecial ? '24px' : '12px'
@@ -190,11 +171,6 @@ export class AppComponent implements AfterViewInit, OnInit {
190171
// #docregion trackById
191172
trackById(index: number, item: any): number { return item['id']; }
192173
// #enddocregion trackById
193-
194-
val = 2;
195-
// villainImageUrl = 'http://www.clker.com/cliparts/u/s/y/L/x/9/villain-man-hi.png'
196-
// Public Domain terms of use http://www.clker.com/disclaimer.html
197-
villainImageUrl = 'images/villain.png';
198174
}
199175

200176
// helper to track changes to viewChildren

public/docs/_examples/template-syntax/ts/src/app/hero-detail.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Hero } from './hero';
1212
inputs: ['hero'],
1313
outputs: ['deleteRequest'],
1414
// #enddocregion input-output-2
15-
styles: ['button { margin-left: 8px} div {margin: 8px 0} img {height:24px}'],
15+
styles: ['button {margin-left: 8px} div {margin: 8px 0} img {height:24px}'],
1616
// #docregion template-1
1717
template: `
1818
<div>
@@ -34,7 +34,7 @@ export class HeroDetailComponent {
3434
lineThrough = '';
3535
@Input() prefix = '';
3636

37-
// #docregion deleteRequest
37+
// #docregion deleteRequest
3838
// This component make a request but it can't actually delete a hero.
3939
deleteRequest = new EventEmitter<Hero>();
4040

@@ -44,7 +44,7 @@ export class HeroDetailComponent {
4444
this.lineThrough = this.lineThrough ? '' : 'line-through';
4545
// #docregion deleteRequest
4646
}
47-
// #enddocregion deleteRequest
47+
// #enddocregion deleteRequest
4848
}
4949

5050
@Component({

public/docs/_examples/template-syntax/ts/src/app/hero-form.component.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div id=heroForm>
1+
<div id="heroForm">
22
<!-- #docregion -->
33
<form (ngSubmit)="onSubmit(heroForm)" #heroForm="ngForm">
44
<div class="form-group">
@@ -10,7 +10,6 @@
1010
</form>
1111
<div [hidden]="!heroForm.form.valid">
1212
{{submitMessage}}
13-
<div>
13+
</div>
1414
<!-- #enddocregion -->
1515
</div>
16-

public/docs/_examples/template-syntax/ts/src/app/hero.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
export class Hero {
2-
static nextId = 1;
2+
static nextId = 0;
33

44
static heroes: Hero[] = [
55
new Hero(
6-
325,
6+
null,
77
'Hercules',
88
'happy',
99
new Date(1970, 1, 25),
10-
'http://www.imdb.com/title/tt0065832/'
10+
'http://www.imdb.com/title/tt0065832/',
11+
325
1112
),
1213
new Hero(1, 'Mr. Nice', 'happy'),
1314
new Hero(2, 'Narco', 'sad' ),

0 commit comments

Comments
 (0)