Skip to content

Commit 48e7af3

Browse files
committed
docs(template-syntax/dart): updates to match TS
- Propagates TS-side changes: - update angular#2639 - new two-way binding section, and - fix angular#2687 - invalid attr syntax - Fixes - angular#1898 - currency symbols - angular#2748 - Dart template-syntax e2e is failing - angular#2749 - deprecated `[className]`
1 parent 08ff17d commit 48e7af3

File tree

5 files changed

+75
-32
lines changed

5 files changed

+75
-32
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:angular2/common.dart';
88
import 'hero.dart';
99
import 'hero_detail_component.dart';
1010
import 'my_click_directive.dart';
11+
import 'my_sizer_component.dart';
1112

1213
enum Color { red, green, blue }
1314

@@ -18,7 +19,8 @@ enum Color { red, green, blue }
1819
HeroDetailComponent,
1920
BigHeroDetailComponent,
2021
MyClickDirective,
21-
MyClickDirective2
22+
MyClickDirective2,
23+
MySizerComponent
2224
])
2325
class AppComponent implements OnInit, AfterViewInit {
2426
@override
@@ -165,6 +167,7 @@ class AppComponent implements OnInit, AfterViewInit {
165167
bool isItalic = false;
166168
bool isBold = false;
167169
String fontSize = 'large';
170+
String fontSizePx = '14';
168171

169172
Map<String, String> setStyle() {
170173
return {

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

+21-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h1>Template Syntax</h1>
1414
</div>
1515
<br>
1616
<a href="#event-binding">Event Binding</a><br>
17-
17+
<a href="#two-way">Two-way Binding</a><br>
1818
<br>
1919
<div>Directives</div>
2020
<div style="margin-left:8px">
@@ -242,9 +242,6 @@ <h3>
242242

243243
<button [attr.disabled]="!isUnchanged">Disabled as well</button>
244244

245-
<!-- can't remove it with [attr.disabled] either -->
246-
<button disabled [attr.disabled]>Still disabled</button>
247-
248245
<!-- we'd have to remove it with property binding -->
249246
<button disabled [disabled]="false">Enabled (but inert)</button>
250247
</div>
@@ -262,7 +259,7 @@ <h3>
262259
<!-- #docregion class-binding-2 -->
263260
<!-- reset/override all class names with a binding -->
264261
<div class="bad curly special"
265-
[className]="badCurly">Bad curly</div>
262+
[class]="badCurly">Bad curly</div>
266263
<!-- #enddocregion class-binding-2 -->
267264

268265
<!-- #docregion class-binding-3 -->
@@ -349,6 +346,24 @@ <h3>
349346
</div>
350347
<!-- #enddocregion event-binding-propagation -->
351348
<br><br>
349+
<a class="to-toc" href="#toc">top</a>
350+
351+
<hr><h2 id="two-way">Two-way Binding</h2>
352+
<div id="two-way-1">
353+
<!-- #docregion two-way-1 -->
354+
<my-sizer [(size)]="fontSizePx"></my-sizer>
355+
<div [style.font-size.px]="fontSizePx">Resizable Text</div>
356+
<!-- #enddocregion two-way-1 -->
357+
<label>FontSize (px): <input [(ngModel)]="fontSizePx"></label>
358+
</div>
359+
<br>
360+
<div id="two-way-2">
361+
<h3>De-sugared two-way binding</h3>
362+
<!-- #docregion two-way-2 -->
363+
<my-sizer [size]="fontSizePx" (sizeChange)="fontSizePx=$event"></my-sizer>
364+
<!-- #enddocregion two-way-2 -->
365+
</div>
366+
<br><br>
352367

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

@@ -746,7 +761,7 @@ <h4>Example Form</h4>
746761

747762
<div>
748763
<!-- pipe price to USD and display the $ symbol -->
749-
<label>Price: </label>{{product['price'] | currency:'USD':false}}
764+
<label>Price: </label>{{product['price'] | currency:'USD':true}}
750765
</div>
751766

752767
<a class="to-toc" href="#toc">top</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// #docregion
2+
import 'dart:math';
3+
import 'package:angular2/core.dart';
4+
5+
@Component(
6+
selector: 'my-sizer',
7+
template: '''
8+
<div>
9+
<button (click)="dec()" title="smaller">-</button>
10+
<button (click)="inc()" title="bigger">+</button>
11+
<label [style.font-size.px]="size">FontSize: {{size}}px</label>
12+
</div>''')
13+
class MySizerComponent {
14+
static final defaultPxSize = 14;
15+
16+
@Input()
17+
String size;
18+
19+
@Output()
20+
var sizeChange = new EventEmitter<String>();
21+
22+
void dec() => resize(-1);
23+
void inc() => resize(1);
24+
25+
void resize(num delta) {
26+
final numSize = num.parse(size, (_) => defaultPxSize);
27+
size = min(40, max(8, numSize + delta)).toString();
28+
sizeChange.emit(size);
29+
}
30+
}

public/docs/dart/latest/guide/template-syntax.jade

-10
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ block dart-type-exception-example
4848
In checked mode, the code above will result in a type exception:
4949
`String` isn't a subtype of `Hero`.
5050

51-
block dart-class-binding-bug
52-
.callout.is-helpful
53-
header Angular Issue #6901
54-
:marked
55-
Issue [#6901][6901] prevents us from using `[class]`. As is illustrated
56-
above, in the meantime we can achieve the same effect by binding to
57-
`className`.
58-
59-
[6901]: http://github.com/angular/angular/issues/6901
60-
6151
block style-property-name-dart-diff
6252
.callout.is-helpful
6353
header Dart difference: Style property names

public/docs/ts/_cache/guide/template-syntax.jade

+20-15
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,6 @@ code-example(format="nocode").
668668
We can replace that with a binding to a string of the desired class names; this is an all-or-nothing, replacement binding.
669669
+makeExample('template-syntax/ts/app/app.component.html', 'class-binding-2')(format=".")
670670

671-
block dart-class-binding-bug
672-
//- N/A
673-
674671
:marked
675672
Finally, we can bind to a specific class name.
676673
Angular adds the class when the template expression evaluates to #{_truthy}.
@@ -854,35 +851,43 @@ block style-property-name-dart-diff
854851
Angular offers a special _two-way data binding_ syntax for this purpose, **`[(x)]`**.
855852
The `[(x)]` syntax combines the brackets
856853
of _Property Binding_, `[x]`, with the parentheses of _Event Binding_, `(x)`.
854+
857855
.callout.is-important
858856
header [( )] = banana in a box
859857
:marked
860858
Visualize a *banana in a box* to remember that the parentheses go _inside_ the brackets.
859+
861860
:marked
862861
The `[(x)]` syntax is easy to demonstrate when the element has a settable property called `x`
863862
and a corresponding event named `xChange`.
864-
Here's a `SizerComponent` that fits the pattern.
863+
Here's a `MySizerComponent` that fits the pattern.
865864
It has a `size` value property and a companion `sizeChange` event:
866-
+makeExample('template-syntax/ts/app/sizer.component.ts', null, 'app/sizer.component.ts')
865+
866+
+makeExample('app/my-sizer.component.ts')
867+
867868
:marked
868869
The initial `size` is an input value from a property binding.
869870
Clicking the buttons increases or decreases the `size`, within min/max values constraints,
870871
and then raises (_emits_) the `sizeChange` event with the adjusted size.
871872

872-
Here's an example in which the `AppComponent.fontSize` is two-way bound to the `SizerComponent`:
873-
+makeExample('template-syntax/ts/app/app.component.html', 'two-way-1')(format=".")
873+
Here's an example in which the `AppComponent.fontSizePx` is two-way bound to the `MySizerComponent`:
874+
875+
+makeExcerpt('app/app.component.html', 'two-way-1', '')
876+
874877
:marked
875-
The `AppComponent.fontSize` establishes the initial `SizerComponent.size` value.
876-
Clicking the buttons updates the `AppComponent.fontSize` via the two-way binding.
877-
The revised `AppComponent.fontSize` value flows through to the _style_ binding, making the displayed text bigger or smaller.
878-
Try it in the <live-example>live example</live-example>.
878+
The `AppComponent.fontSizePx` establishes the initial `MySizerComponent.size` value.
879+
Clicking the buttons updates the `AppComponent.fontSizePx` via the two-way binding.
880+
The revised `AppComponent.fontSizePx` value flows through to the _style_ binding, making the displayed text bigger or smaller.
881+
Try it in the <live-example></live-example>.
879882

880883
The two-way binding syntax is really just syntactic sugar for a _property_ binding and an _event_ binding.
881-
Angular _desugars_ the `SizerComponent` binding into this:
882-
+makeExample('template-syntax/ts/app/app.component.html', 'two-way-2')(format=".")
884+
Angular _desugars_ the `MySizerComponent` binding into this:
885+
886+
+makeExcerpt('app/app.component.html', 'two-way-2', '')
887+
883888
:marked
884-
The `$event` variable contains the payload of the `SizerComponent.sizeChange` event.
885-
Angular assigns the `$event` value to the `AppComponent.fontSize` when the user clicks the buttons.
889+
The `$event` variable contains the payload of the `MySizerComponent.sizeChange` event.
890+
Angular assigns the `$event` value to the `AppComponent.fontSizePx` when the user clicks the buttons.
886891

887892
Clearly the two-way binding syntax is a great convenience compared to separate property and event bindings.
888893

0 commit comments

Comments
 (0)