From a8ad96eb169d80d1e0cf7066e53cc33ce6d1604a Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Thu, 9 Mar 2017 12:13:17 -0800 Subject: [PATCH] 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 `` 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. --- .../ts/src/app/app.component.html | 48 +- .../ts/src/app/app.component.ts | 48 +- .../ts/src/app/hero-detail.component.ts | 6 +- .../ts/src/app/hero-form.component.html | 5 +- .../template-syntax/ts/src/app/hero.ts | 7 +- .../docs/ts/latest/guide/template-syntax.jade | 540 ++++++++++++------ 6 files changed, 403 insertions(+), 251 deletions(-) diff --git a/public/docs/_examples/template-syntax/ts/src/app/app.component.html b/public/docs/_examples/template-syntax/ts/src/app/app.component.html index b3d6c29be5..e58460bf89 100644 --- a/public/docs/_examples/template-syntax/ts/src/app/app.component.html +++ b/public/docs/_examples/template-syntax/ts/src/app/app.component.html @@ -158,15 +158,15 @@
- + -
+


- +
click me
@@ -176,9 +176,9 @@
Hero Name: - + - {{heroName}} + {{name}}


@@ -193,7 +193,7 @@

- @@ -349,7 +349,7 @@ button

Style Binding

- + @@ -402,14 +402,14 @@ button
- +
- +
@@ -460,21 +460,21 @@ bindon-ngModel [ngModel]="currentHero.name" (ngModelChange)="currentHero.name=$event"> -(ngModelChange) = "...name=$event" +(ngModelChange)="...name=$event"
-(ngModelChange) = "setUppercaseName($event)" +(ngModelChange)="setUppercaseName($event)" top

NgClass Binding

-

currentClasses returns {{currentClasses | json}}

+

currentClasses is {{currentClasses | json}}

This div is initially saveable, unchanged, and special
@@ -489,7 +489,7 @@ bindon-ngModel
This div should be {{ canSave ? "": "not"}} saveable, {{ isUnchanged ? "unchanged" : "modified" }} and, - {{ isSpecial ? "": "not"}} special after clicking "refresh".
+ {{ isSpecial ? "": "not"}} special after clicking "Refresh".

This div is special
@@ -504,12 +504,12 @@ bindon-ngModel
- This div is x-large. + This div is x-large or smaller.
-

[ngStyle] binding to `currentStyles` - CSS property names

-

currentStyles returns {{currentStyles | json}}

+

[ngStyle] binding to currentStyles - CSS property names

+

currentStyles is {{currentStyles | json}}

This div is initially italic, normal weight, and extra large (24px). @@ -526,7 +526,7 @@ bindon-ngModel
This div should be {{ canSave ? "italic": "plain"}}, {{ isUnchanged ? "normal weight" : "bold" }} and, - {{ isSpecial ? "extra large": "normal size"}} after clicking "refresh".
+ {{ isSpecial ? "extra large": "normal size"}} after clicking "Refresh".
top @@ -655,14 +655,12 @@ bindon-ngModel

NgSwitch Binding

-
Pick your favorite hero
-

- - - -

+

Pick your favorite hero

+
+ +
diff --git a/public/docs/_examples/template-syntax/ts/src/app/app.component.ts b/public/docs/_examples/template-syntax/ts/src/app/app.component.ts index 166948362f..0b25908a01 100644 --- a/public/docs/_examples/template-syntax/ts/src/app/app.component.ts +++ b/public/docs/_examples/template-syntax/ts/src/app/app.component.ts @@ -31,8 +31,8 @@ export class AppComponent implements AfterViewInit, OnInit { ngAfterViewInit() { // Detect effects of NgForTrackBy - trackChanges(this.heroesNoTrackBy, () => this.heroesNoTrackByCount += 1); - trackChanges(this.heroesWithTrackBy, () => this.heroesWithTrackByCount += 1); + trackChanges(this.heroesNoTrackBy, () => this.heroesNoTrackByCount++); + trackChanges(this.heroesWithTrackBy, () => this.heroesWithTrackByCount++); } @ViewChildren('noTrackBy') heroesNoTrackBy: QueryList; @@ -42,6 +42,7 @@ export class AppComponent implements AfterViewInit, OnInit { alert = alerter; badCurly = 'bad curly'; classes = 'special'; + help = ''; callFax(value: string) {this.alert(`Faxing ${value} ...`); } callPhone(value: string) {this.alert(`Calling ${value} ...`); } @@ -83,17 +84,9 @@ export class AppComponent implements AfterViewInit, OnInit { title = 'Template Syntax'; - getStyles(el: Element) { - let styles = window.getComputedStyle(el); - let showStyles = {}; - for (let p in this.currentStyles) { // only interested in these styles - showStyles[p] = styles[p]; - } - return JSON.stringify(showStyles); - } - - getVal() { return this.val; } + getVal(): number { return 2; } + name: string = Hero.heroes[0].name; hero: Hero; // defined to demonstrate template context precedence heroes: Hero[]; @@ -107,18 +100,16 @@ export class AppComponent implements AfterViewInit, OnInit { // heroImageUrl = 'http://www.wpclipart.com/cartoon/people/hero/hero_silhoutte_T.png'; // Public Domain terms of use: http://www.wpclipart.com/terms.html heroImageUrl = 'images/hero.png'; + // villainImageUrl = 'http://www.clker.com/cliparts/u/s/y/L/x/9/villain-man-hi.png' + // Public Domain terms of use http://www.clker.com/disclaimer.html + villainImageUrl = 'images/villain.png'; iconUrl = 'images/ng-logo.png'; isActive = false; isSpecial = true; isUnchanged = true; - nullHero: Hero = null; - - onCancel(event: KeyboardEvent) { - let evtMsg = event ? ' Event target is ' + (event.target).innerHTML : ''; - this.alert('Canceled.' + evtMsg); - } + get nullHero(): Hero { return null; } onClickMe(event: KeyboardEvent) { let evtMsg = event ? ' Event target class is ' + (event.target).className : ''; @@ -128,9 +119,10 @@ export class AppComponent implements AfterViewInit, OnInit { onSave(event: KeyboardEvent) { let evtMsg = event ? ' Event target is ' + (event.target).innerText : ''; this.alert('Saved.' + evtMsg); + if (event) { event.stopPropagation(); } } - onSubmit() { /* referenced but not used */} + onSubmit() {/* referenced but not used */} product = { name: 'frimfram', @@ -144,17 +136,6 @@ export class AppComponent implements AfterViewInit, OnInit { this.heroesWithTrackByCountReset = 0; } - private samenessCount = 5; - moreOfTheSame() { this.samenessCount++; }; - get sameAsItEverWas() { - let result: string[] = Array(this.samenessCount); - for ( let i = result.length; i-- > 0; ) { result[i] = 'same as it ever was ...'; } - return result; - // return [1,2,3,4,5].map(id => { - // return {id:id, text: 'same as it ever was ...'}; - // }); - } - setUppercaseName(name: string) { this.currentHero.name = name.toUpperCase(); } @@ -174,8 +155,8 @@ export class AppComponent implements AfterViewInit, OnInit { // #docregion setStyles currentStyles: {}; setCurrentStyles() { + // CSS styles: set per current state of component properties this.currentStyles = { - // CSS styles: set per current state of component properties 'font-style': this.canSave ? 'italic' : 'normal', 'font-weight': !this.isUnchanged ? 'bold' : 'normal', 'font-size': this.isSpecial ? '24px' : '12px' @@ -190,11 +171,6 @@ export class AppComponent implements AfterViewInit, OnInit { // #docregion trackById trackById(index: number, item: any): number { return item['id']; } // #enddocregion trackById - - val = 2; - // villainImageUrl = 'http://www.clker.com/cliparts/u/s/y/L/x/9/villain-man-hi.png' - // Public Domain terms of use http://www.clker.com/disclaimer.html - villainImageUrl = 'images/villain.png'; } // helper to track changes to viewChildren diff --git a/public/docs/_examples/template-syntax/ts/src/app/hero-detail.component.ts b/public/docs/_examples/template-syntax/ts/src/app/hero-detail.component.ts index 486e6ac370..725849d692 100644 --- a/public/docs/_examples/template-syntax/ts/src/app/hero-detail.component.ts +++ b/public/docs/_examples/template-syntax/ts/src/app/hero-detail.component.ts @@ -12,7 +12,7 @@ import { Hero } from './hero'; inputs: ['hero'], outputs: ['deleteRequest'], // #enddocregion input-output-2 - styles: ['button { margin-left: 8px} div {margin: 8px 0} img {height:24px}'], + styles: ['button {margin-left: 8px} div {margin: 8px 0} img {height:24px}'], // #docregion template-1 template: `
@@ -34,7 +34,7 @@ export class HeroDetailComponent { lineThrough = ''; @Input() prefix = ''; -// #docregion deleteRequest + // #docregion deleteRequest // This component make a request but it can't actually delete a hero. deleteRequest = new EventEmitter(); @@ -44,7 +44,7 @@ export class HeroDetailComponent { this.lineThrough = this.lineThrough ? '' : 'line-through'; // #docregion deleteRequest } -// #enddocregion deleteRequest + // #enddocregion deleteRequest } @Component({ diff --git a/public/docs/_examples/template-syntax/ts/src/app/hero-form.component.html b/public/docs/_examples/template-syntax/ts/src/app/hero-form.component.html index bbd417e304..2182060439 100644 --- a/public/docs/_examples/template-syntax/ts/src/app/hero-form.component.html +++ b/public/docs/_examples/template-syntax/ts/src/app/hero-form.component.html @@ -1,4 +1,4 @@ -
+
@@ -10,7 +10,6 @@
{{submitMessage}} -
+
- diff --git a/public/docs/_examples/template-syntax/ts/src/app/hero.ts b/public/docs/_examples/template-syntax/ts/src/app/hero.ts index 6331b62a7b..f8cc3b16a6 100644 --- a/public/docs/_examples/template-syntax/ts/src/app/hero.ts +++ b/public/docs/_examples/template-syntax/ts/src/app/hero.ts @@ -1,13 +1,14 @@ export class Hero { - static nextId = 1; + static nextId = 0; static heroes: Hero[] = [ new Hero( - 325, + null, 'Hercules', 'happy', new Date(1970, 1, 25), - 'http://www.imdb.com/title/tt0065832/' + 'http://www.imdb.com/title/tt0065832/', + 325 ), new Hero(1, 'Mr. Nice', 'happy'), new Hero(2, 'Narco', 'sad' ), diff --git a/public/docs/ts/latest/guide/template-syntax.jade b/public/docs/ts/latest/guide/template-syntax.jade index c7842ecdb7..6b25a680d4 100644 --- a/public/docs/ts/latest/guide/template-syntax.jade +++ b/public/docs/ts/latest/guide/template-syntax.jade @@ -6,7 +6,7 @@ block includes - var __new_op = 'new'; - var __objectAsMap = 'object'; -// The docs standard h4 style uppercases, making code terms unreadable. Override it. +//- The docs standard h4 style uppercases, making code terms unreadable. Override it. style. h4 {font-size: 17px !important; text-transform: none !important;} .syntax { font-family: Consolas, 'Lucida Sans', Courier, sans-serif; color: black; font-size: 85%; } @@ -22,6 +22,7 @@ style. a#toc :marked ### Table of contents + This guide covers the basic elements of the Angular template syntax, elements you'll need to construct the view: * [HTML in templates](#html) @@ -34,16 +35,16 @@ a#toc * [Event binding ( (event) )](#event-binding) * [Two-way data binding ( [(...)] )](#two-way) * [Built-in directives](#directives) - * [Attribute directives](#attribute-directives) - * [NgClass](#ngClass) - * [NgStyle](#ngStyle) - * [NgModel ([(ngModel)]) ](#ngModel) - * [Structural directives](#structural-directives) - * [NgIf](#ngIf) - * [NgFor](#ngFor) - * [Template input variables](#template-input-variables) - * [microsyntax](#microsyntax) - * [The NgSwitch directives](#ngSwitch) + * [Built-in attribute directives](#attribute-directives) + * [NgClass](#ngClass) + * [NgStyle](#ngStyle) + * [NgModel ([(ngModel)]) ](#ngModel) + * [Built-in structural directives](#structural-directives) + * [NgIf](#ngIf) + * [NgFor](#ngFor) + * [Template input variables](#template-input-variables) + * [Microsyntax](#microsyntax) + * [The NgSwitch directives](#ngSwitch) * [Template reference variables ( #var )](#ref-vars) * [Input and output properties ( @Input and @Output )](#inputs-outputs) * [Template expression operators](#expression-operators) @@ -57,17 +58,13 @@ a#toc a#html :marked ## HTML in templates - HTML is the language of the Angular template. - The [QuickStart](../quickstart.html) application has a template that is pure HTML: -code-example(language="html" escape="html"). -

Hello Angular

- -:marked + HTML is the language of the Angular template. Almost all HTML syntax is valid template syntax. The `