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

Commit 9e9666b

Browse files
chalinkwalrath
authored andcommitted
docs(template-syntax/dart): updates to match TS (#2751)
* docs(template-syntax): refresh _cache * docs(template-syntax/dart): updates to match TS - Propagates TS-side changes: - update #2639 - new two-way binding section, and - fix #2687 - invalid attr syntax - Fixes - #1898 - currency symbols - #2748 - Dart template-syntax e2e is failing - #2749 - deprecated `[className]` * updated _cache file following Kathy's post-review edits * Post Ward's review w/ cache updated - Keep `my-` and `my` prefixes on selectors (for components and directives, respectively). - Drop `my-` from file names. - Drop `My` as component class prefix.
1 parent 5dcffd6 commit 9e9666b

File tree

6 files changed

+186
-101
lines changed

6 files changed

+186
-101
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import 'package:angular2/common.dart';
77

88
import 'hero.dart';
99
import 'hero_detail_component.dart';
10-
import 'my_click_directive.dart';
10+
import 'click_directive.dart';
11+
import '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

+23-8
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 -->
@@ -309,9 +306,9 @@ <h3>
309306
<div>
310307
<!-- #docregion event-binding-3 -->
311308
<!-- `myClick` is an event on the custom `MyClickDirective` -->
312-
<!-- #docregion my-click -->
309+
<!-- #docregion myClick -->
313310
<div (myClick)="clickMessage=$event">click with myClick</div>
314-
<!-- #enddocregion my-click -->
311+
<!-- #enddocregion myClick -->
315312
<!-- #enddocregion event-binding-3 -->
316313
{{clickMessage}}
317314
</div>
@@ -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>

public/docs/_examples/template-syntax/dart/lib/my_click_directive.dart renamed to public/docs/_examples/template-syntax/dart/lib/click_directive.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import 'package:angular2/core.dart';
55

66
@Directive(selector: '[myClick]')
77
class MyClickDirective {
8-
// #docregion my-click-output-1
8+
// #docregion output-myClick
99
// @Output(alias) [type info] propertyName = ...
1010
@Output('myClick') final EventEmitter clicks = new EventEmitter<String>();
1111

12-
// #enddocregion my-click-output-1
12+
// #enddocregion output-myClick
1313
bool _toggle = false;
1414

1515
MyClickDirective(ElementRef el) {
@@ -21,14 +21,14 @@ class MyClickDirective {
2121
}
2222
}
2323

24-
// #docregion my-click-output-2
24+
// #docregion output-myClick2
2525
@Directive(
26-
// #enddocregion my-click-output-2
26+
// #enddocregion output-myClick2
2727
selector: '[myClick2]',
28-
// #docregion my-click-output-2
28+
// #docregion output-myClick2
2929
// ...
3030
outputs: const ['clicks:myClick']) // propertyName:alias
31-
// #enddocregion my-click-output-2
31+
// #enddocregion output-myClick2
3232
class MyClickDirective2 {
3333
final EventEmitter clicks = new EventEmitter<String>();
3434
bool _toggle = false;
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

0 commit comments

Comments
 (0)