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

Commit 3c50a15

Browse files
committed
updated guide/template-syntax for dart and ts
1 parent a942626 commit 3c50a15

File tree

9 files changed

+426
-645
lines changed

9 files changed

+426
-645
lines changed

public/_includes/_util-fns.jade

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- var _an = 'an';
2222

2323
//- TS arrays vs. Dart lists
24+
- var _Array = 'Array';
2425
- var _array = 'array';
2526
//- Deprecate now that we have the articles _a and _an
2627
- var _an_array = 'an array';
@@ -32,15 +33,18 @@
3233
//- Location of sample code
3334
- var _liveLink = 'live link';
3435

36+
//- Other
37+
- var _truthy = 'truthy';
38+
- var _falsey = 'falsey';
3539

3640
//- Used to prefix identifiers that are private. In Dart this will be '_'.
3741
- var _priv = '';
3842

3943
//- Use to conditionally include the block that follows +ifDocsFor(...).
4044
//- Generally favor use of Jade named blocks instead. ifDocsFor is convenient
4145
//- for prose that should appear only in one language version.
42-
mixin ifDocsFor(lang)
43-
if _docsFor.toLowerCase() === lang.toLowerCase()
46+
mixin ifDocsFor(langPattern)
47+
if _docsFor.toLowerCase().match(langPattern.toLowerCase())
4448
block
4549

4650
//- Use to map inlined (prose) TS paths into, say, Dart paths via the

public/docs/_examples/template-syntax/dart/example-config.json

Whitespace-only changes.

public/docs/_examples/template-syntax/dart/lib/app_component.dart

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:convert';
33
import 'dart:html';
44

55
import 'package:angular2/core.dart';
6+
import 'package:angular2/common.dart';
67

78
import 'hero.dart';
89
import 'hero_detail_component.dart';
@@ -40,7 +41,9 @@ class AppComponent implements OnInit, AfterViewInit {
4041
bool isSpecial = true;
4142
bool isUnchanged = true;
4243
bool isSelected = false;
44+
final Color colorRed = Color.red;
4345
Color color = Color.red;
46+
var colorEnum = Color;
4447

4548
List<Hero> heroes;
4649
Hero currentHero;
@@ -56,7 +59,7 @@ class AppComponent implements OnInit, AfterViewInit {
5659
final Hero nullHero = null;
5760
Map product = {'name': 'frimfram', 'price': 42};
5861
FormElement form;
59-
String clickity = '';
62+
String clicked = '';
6063
String clickMessage = '';
6164
String clickMessage2 = '';
6265
final String iconUrl = 'assets/images/ng-logo.png';
@@ -87,14 +90,14 @@ class AppComponent implements OnInit, AfterViewInit {
8790

8891
int getVal() => val;
8992

90-
void onCancel(MouseEvent event) {
91-
DivElement el = event.target;
93+
void onCancel(UIEvent event) {
94+
HtmlElement el = event?.target;
9295
var evtMsg = event != null ? 'Event target is ${el.innerHtml}.' : '';
9396
alerter('Canceled. $evtMsg');
9497
}
9598

96-
void onClickMe(MouseEvent event) {
97-
DivElement el = event.target;
99+
void onClickMe(UIEvent event) {
100+
HtmlElement el = event?.target;
98101
var evtMsg = event != null ? 'Event target class is ${el.className}.' : '';
99102
alerter('Click me. $evtMsg');
100103
}
@@ -103,9 +106,10 @@ class AppComponent implements OnInit, AfterViewInit {
103106
alerter('Deleted hero: ${hero?.firstName}');
104107
}
105108

106-
bool onSave([MouseEvent event = null]) {
109+
bool onSave([UIEvent event = null]) {
110+
HtmlElement el = event?.target;
107111
var evtMsg =
108-
event != null ? ' Event target is ${event.target.innerHtml}.' : '';
112+
event != null ? ' Event target is ${el.innerHtml}.' : '';
109113
alerter('Saved. $evtMsg');
110114
return false;
111115
}

public/docs/_examples/template-syntax/dart/lib/app_component.html

+65-72
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ <h1>Template Syntax</h1>
3131
</div>
3232
<br>
3333
<a href="#star-prefix">* prefix and &lt;template&gt;</a><br>
34-
<a href="#local-vars">Template local variables</a><br>
34+
<a href="#ref-vars">Template reference variables</a><br>
3535
<a href="#inputs-and-outputs">Inputs and outputs</a><br>
3636
<a href="#pipes">Pipes</a><br>
3737
<a href="#safe-navigation-operator">Safe navigation operator <i>?.</i></a><br>
38-
<!--<a href="#enums">Enums</a><br>-->
38+
<a href="#enums">Enums</a><br>
3939

4040
<!-- Interpolation and expressions -->
4141
<hr><h2 id="interpolation">Interpolation</h2>
@@ -105,9 +105,9 @@ <h3>
105105
<!-- #docregion event-binding-syntax-1 -->
106106
<button (click) = "onSave()">Save</button>
107107
<hero-detail (deleteRequest)="deleteHero()"></hero-detail>
108-
<div (myClick)="clickity=$event">click me</div>
108+
<div (myClick)="clicked=$event">click me</div>
109109
<!-- #enddocregion event-binding-syntax-1 -->
110-
{{clickity}}
110+
{{clicked}}
111111
<br><br>
112112

113113
<div>
@@ -184,15 +184,14 @@ <h3>
184184
<!-- #enddocregion property-binding-5 -->
185185

186186
<!-- #docregion property-binding-6 -->
187-
<!-- BAD! HeroDetailComponent.hero expects a Hero object,
188-
not the string "currentHero".
189-
190-
<hero-detail hero="currentHero"></hero-detail> -->
187+
<!-- ERROR: HeroDetailComponent.hero expects a
188+
Hero object, not the string "currentHero" -->
191189
<!-- #enddocregion property-binding-6 -->
192-
193-
<!-- In checked mode, uncommenting the hero-detail above causes this:
194-
EXCEPTION: type 'String' is not a subtype of type 'Hero' of 'value'. -->
195-
190+
<div *ngIf="false">
191+
<!-- #docregion property-binding-6 -->
192+
<hero-detail hero="currentHero"></hero-detail>
193+
<!-- #enddocregion property-binding-6 -->
194+
</div>
196195
<!-- #docregion property-binding-7 -->
197196
<hero-detail prefix="You are my" [hero]="currentHero"></hero-detail>
198197
<!-- #enddocregion property-binding-7 -->
@@ -202,7 +201,7 @@ <h3>
202201
Property bound: <img [src]="heroImageUrl">
203202

204203
<div>The interpolated title is {{title}}</div>
205-
<div [textContent]="'The [textContent] title is '+title"></div>
204+
<div [innerHTML]="'The [innerHTML] title is '+title"></div>
206205
<!-- #enddocregion property-binding-vs-interpolation -->
207206

208207
<a class="to-toc" href="#toc">top</a>
@@ -258,9 +257,7 @@ <h3>
258257
<!-- #docregion class-binding-2 -->
259258
<!-- reset/override all class names with a binding -->
260259
<div class="bad curly special"
261-
[class]="badCurly">Bad curly</div>
262-
<p><b>Note:</b> "Bad curly" should be smaller but isn't, due to
263-
<a href="http://github.com/angular/angular/issues/6901">issue #6901</a>.</p>
260+
[className]="badCurly">Bad curly</div>
264261
<!-- #enddocregion class-binding-2 -->
265262

266263
<!-- #docregion class-binding-3 -->
@@ -374,15 +371,15 @@ <h3>Result: {{currentHero.firstName}}</h3>
374371
<br>
375372
<!-- #docregion NgModel-3 -->
376373
<input
377-
[ngModel]="currentHero.firstName"
378-
(ngModelChange)="currentHero.firstName=$event">
374+
[ngModel]="currentHero.firstName"
375+
(ngModelChange)="currentHero.firstName=$event">
379376
<!-- #enddocregion NgModel-3 -->
380377
(ngModelChange) = "...firstName=$event"
381378
<br>
382379
<!-- #docregion NgModel-4 -->
383380
<input
384-
[ngModel]="currentHero.firstName"
385-
(ngModelChange)="setUpperCaseFirstName($event)">
381+
[ngModel]="currentHero.firstName"
382+
(ngModelChange)="setUpperCaseFirstName($event)">
386383
<!-- #enddocregion NgModel-4 -->
387384
(ngModelChange) = "setUpperCaseFirstName($event)"
388385
<br>
@@ -443,7 +440,7 @@ <h3>Use setStyles() - CSS property names</h3>
443440
<!-- #enddocregion NgIf-1 -->
444441

445442
<!-- #docregion NgIf-2 -->
446-
<!-- not displayed because nullHero is false.
443+
<!-- because of the ngIf guard
447444
`nullHero.firstName` never has a chance to fail -->
448445
<div *ngIf="nullHero != null">Hello, {{nullHero.firstName}}</div>
449446

@@ -487,33 +484,33 @@ <h3>Use setStyles() - CSS property names</h3>
487484
</fieldset>
488485

489486
<div class="toe">
490-
<div *ngIf="toeChoice == null">Pick a toe</div>
491-
<div *ngIf="toeChoice != null">
492-
You picked ...
493-
<!-- #docregion NgSwitch, NgSwitch-expanded -->
494-
<span [ngSwitch]="toeChoice">
487+
<div *ngIf="toeChoice == null">Pick a toe</div>
488+
<div *ngIf="toeChoice != null">
489+
You picked ...
490+
<!-- #docregion NgSwitch, NgSwitch-expanded -->
491+
<span [ngSwitch]="toeChoice">
495492
<!-- #enddocregion NgSwitch -->
496493

497-
<!-- with *NgSwitch -->
498-
<!-- #docregion NgSwitch -->
499-
<span *ngSwitchWhen="'Eenie'">Eenie</span>
500-
<span *ngSwitchWhen="'Meanie'">Meanie</span>
501-
<span *ngSwitchWhen="'Miney'">Miney</span>
502-
<span *ngSwitchWhen="'Moe'">Moe</span>
503-
<span *ngSwitchDefault>other</span>
504-
<!-- #enddocregion NgSwitch -->
505-
506-
<!-- with <template> -->
507-
<template ngSwitchWhen="Eenie"><span>Eenie</span></template>
508-
<template ngSwitchWhen="Meanie"><span>Meanie</span></template>
509-
<template ngSwitchWhen="Miney"><span>Miney</span></template>
510-
<template ngSwitchWhen="Moe"><span>Moe</span></template>
511-
<template ngSwitchDefault><span>other</span></template>
494+
<!-- with *NgSwitch -->
495+
<!-- #docregion NgSwitch -->
496+
<span *ngSwitchWhen="'Eenie'">Eenie</span>
497+
<span *ngSwitchWhen="'Meanie'">Meanie</span>
498+
<span *ngSwitchWhen="'Miney'">Miney</span>
499+
<span *ngSwitchWhen="'Moe'">Moe</span>
500+
<span *ngSwitchDefault>other</span>
501+
<!-- #enddocregion NgSwitch -->
502+
503+
<!-- with <template> -->
504+
<template [ngSwitchWhen]="'Eenie'"><span>Eenie</span></template>
505+
<template [ngSwitchWhen]="'Meanie'"><span>Meanie</span></template>
506+
<template [ngSwitchWhen]="'Miney'"><span>Miney</span></template>
507+
<template [ngSwitchWhen]="'Moe'"><span>Moe</span></template>
508+
<template ngSwitchDefault><span>other</span></template>
512509

513510
<!-- #docregion NgSwitch -->
514-
</span>
515-
<!-- #enddocregion NgSwitch, NgSwitch-expanded -->
516-
</div>
511+
</span>
512+
<!-- #enddocregion NgSwitch, NgSwitch-expanded -->
513+
</div>
517514
</div>
518515

519516
<a class="to-toc" href="#toc">top</a>
@@ -620,7 +617,7 @@ <h3>*ngIf expansion</h3>
620617
<p><i>expand to &lt;template&gt;</i></p>
621618
<!-- #docregion Template-2 -->
622619
<template [ngIf]="currentHero != null">
623-
<hero-detail [hero]="currentHero"></hero-detail>
620+
<hero-detail [hero]="currentHero"></hero-detail>
624621
</template>
625622
<!-- #enddocregion Template-2 -->
626623

@@ -644,15 +641,15 @@ <h3>*ngFor expansion</h3>
644641
<!-- ngFor w/ hero-detail Component inside a template element -->
645642
<!-- #docregion Template-4 -->
646643
<template ngFor let-hero [ngForOf]="heroes" [ngForTrackBy]="trackByHeroes">
647-
<hero-detail [hero]="hero"></hero-detail>
644+
<hero-detail [hero]="hero"></hero-detail>
648645
</template>
649646
<!-- #enddocregion Template-4 -->
650647
</div>
651648

652649
<a class="to-toc" href="#toc">top</a>
653650

654-
<!-- template local variable -->
655-
<hr><h2 id="local-vars">Template local variables</h2>
651+
<!-- template reference variable -->
652+
<hr><h2 id="ref-vars">Template reference variables</h2>
656653

657654
<!-- #docregion ref-phone -->
658655
<!-- phone refers to the input element; pass its `value` to an event handler -->
@@ -672,7 +669,7 @@ <h4>Example Form</h4>
672669
<div class="form-group">
673670
<label for="name">Name</label>
674671
<input class="form-control" required ngControl="firstName"
675-
[(ngModel)]="currentHero.firstName">
672+
[(ngModel)]="currentHero.firstName">
676673
</div>
677674
<!-- #docregion ref-form-a -->
678675
<button type="submit" [disabled]="!theForm.form.valid">Submit</button>
@@ -682,7 +679,7 @@ <h4>Example Form</h4>
682679
<br><br>
683680

684681
<!-- btn refers to the button element; show its disabled state -->
685-
<button #btn disabled [textContent]="'disabled by attribute: ' + btn.disabled.toString()"></button>
682+
<button #btn disabled [innerHTML]="'disabled by attribute: ' + btn.disabled.toString()"></button>
686683

687684
<a class="to-toc" href="#toc">top</a>
688685

@@ -708,13 +705,15 @@ <h4>Example Form</h4>
708705
<hr><h2 id="pipes">Pipes</h2>
709706

710707
<!-- #docregion pipes-1 -->
711-
<!-- Force title to uppercase -->
712-
<div>{{ title | uppercase }}</div>
708+
<div>Title through uppercase pipe: {{title | uppercase}}</div>
713709
<!-- #enddocregion pipes-1 -->
714710

715711
<!-- #docregion pipes-2 -->
716-
<!-- Pipe chaining: force title to uppercase, then to lowercase -->
717-
<div>{{ title | uppercase | lowercase }}</div>
712+
<!-- Pipe chaining: convert title to uppercase, then to lowercase -->
713+
<div>
714+
Title through a pipe chain:
715+
{{title | uppercase | lowercase}}
716+
</div>
718717
<!-- #enddocregion pipes-2 -->
719718

720719
<!-- #docregion pipes-3 -->
@@ -723,16 +722,14 @@ <h4>Example Form</h4>
723722
<!-- #enddocregion pipes-3 -->
724723

725724
<!-- #docregion pipes-json -->
726-
<!-- We don't suggest using json for debugging; you'd probably use toString() instead.
727-
Is there a good use for the json pipe in Dart? -->
728-
<!--<div>{{currentHero | json}}</div>-->
725+
<div>{{currentHero}}</div>
729726
<!-- #enddocregion pipes-json -->
730727

731728
<div>Birthdate: {{(currentHero?.birthdate | date:'longDate') | uppercase}}</div>
732729

733730
<div>
734731
<!-- pipe price to USD and display the $ symbol -->
735-
<label>Price: </label>{{product['price'] | currency:'$'}}
732+
<label>Price: </label>{{product['price'] | currency:'USD':false}}
736733
</div>
737734

738735
<a class="to-toc" href="#toc">top</a>
@@ -742,7 +739,7 @@ <h4>Example Form</h4>
742739

743740
<div>
744741
<!-- #docregion safe-1 -->
745-
The title is {{ title }}
742+
The title is {{title}}
746743
<!-- #enddocregion safe-1 -->
747744
</div>
748745

@@ -759,11 +756,10 @@ <h4>Example Form</h4>
759756
</div>
760757

761758

762-
763759
<!--
764760
The null hero's name is {{nullHero.firstName}}
765761
766-
See console log:
762+
See console log:
767763
EXCEPTION: The null object does not have a getter 'firstName'.
768764
-->
769765

@@ -784,19 +780,16 @@ <h4>Example Form</h4>
784780

785781
<a class="to-toc" href="#toc">top</a>
786782

787-
<!-- Todo: discuss this in the Style binding section -->
783+
<!-- TODO: discuss this in the Style binding section -->
788784
<!-- enums in bindings -->
789-
790785
<hr><h2 id="enums">Enums in binding</h2>
791786

792-
<!--<p>The name of the Color.red enum is {{color}}</p>-->
793-
<p>The current color number is {{color}}</p>
794-
<p><button [style.color]="color.toString()" (click)="colorToggle()">Enum Toggle</button>
795-
796-
<a class="to-toc" href="#toc">top</a>
797-
798-
<!-- #docregion my-first-app -->
799-
<h3>My First Angular Application</h3>
800-
<!-- #enddocregion my-first-app -->
787+
<p>
788+
<!-- #docregion enums -->
789+
The name of the Color.red enum is {{colorRed}}.<br>
790+
The current color is {{color}} and its index is {{color.index}}.<br>
791+
<button [style.color]="color.toString()" (click)="colorToggle()">Enum Toggle</button>
792+
<!-- #enddocregion enums -->
793+
</p>
801794

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

0 commit comments

Comments
 (0)