@@ -31,11 +31,11 @@ <h1>Template Syntax</h1>
31
31
</ div >
32
32
< br >
33
33
< a href ="#star-prefix "> * prefix and <template></ a > < br >
34
- < a href ="#local -vars "> Template local variables</ a > < br >
34
+ < a href ="#ref -vars "> Template reference variables</ a > < br >
35
35
< a href ="#inputs-and-outputs "> Inputs and outputs</ a > < br >
36
36
< a href ="#pipes "> Pipes</ a > < br >
37
37
< 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 >
39
39
40
40
<!-- Interpolation and expressions -->
41
41
< hr > < h2 id ="interpolation "> Interpolation</ h2 >
105
105
<!-- #docregion event-binding-syntax-1 -->
106
106
< button (click) = "onSave() "> Save</ button >
107
107
< hero-detail (deleteRequest) ="deleteHero() "> </ hero-detail >
108
- < div (myClick) ="clickity =$event "> click me</ div >
108
+ < div (myClick) ="clicked =$event "> click me</ div >
109
109
<!-- #enddocregion event-binding-syntax-1 -->
110
- {{clickity }}
110
+ {{clicked }}
111
111
< br > < br >
112
112
113
113
< div >
@@ -184,15 +184,14 @@ <h3>
184
184
<!-- #enddocregion property-binding-5 -->
185
185
186
186
<!-- #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" -->
191
189
<!-- #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 >
196
195
<!-- #docregion property-binding-7 -->
197
196
< hero-detail prefix ="You are my " [hero] ="currentHero "> </ hero-detail >
198
197
<!-- #enddocregion property-binding-7 -->
202
201
Property bound: < img [src] ="heroImageUrl ">
203
202
204
203
< 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 >
206
205
<!-- #enddocregion property-binding-vs-interpolation -->
207
206
208
207
< a class ="to-toc " href ="#toc "> top</ a >
258
257
<!-- #docregion class-binding-2 -->
259
258
<!-- reset/override all class names with a binding -->
260
259
< 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 >
264
261
<!-- #enddocregion class-binding-2 -->
265
262
266
263
<!-- #docregion class-binding-3 -->
@@ -374,15 +371,15 @@ <h3>Result: {{currentHero.firstName}}</h3>
374
371
< br >
375
372
<!-- #docregion NgModel-3 -->
376
373
< input
377
- [ngModel] ="currentHero.firstName "
378
- (ngModelChange) ="currentHero.firstName=$event ">
374
+ [ngModel] ="currentHero.firstName "
375
+ (ngModelChange) ="currentHero.firstName=$event ">
379
376
<!-- #enddocregion NgModel-3 -->
380
377
(ngModelChange) = "...firstName=$event"
381
378
< br >
382
379
<!-- #docregion NgModel-4 -->
383
380
< input
384
- [ngModel] ="currentHero.firstName "
385
- (ngModelChange) ="setUpperCaseFirstName($event) ">
381
+ [ngModel] ="currentHero.firstName "
382
+ (ngModelChange) ="setUpperCaseFirstName($event) ">
386
383
<!-- #enddocregion NgModel-4 -->
387
384
(ngModelChange) = "setUpperCaseFirstName($event)"
388
385
< br >
@@ -443,7 +440,7 @@ <h3>Use setStyles() - CSS property names</h3>
443
440
<!-- #enddocregion NgIf-1 -->
444
441
445
442
<!-- #docregion NgIf-2 -->
446
- <!-- not displayed because nullHero is false.
443
+ <!-- because of the ngIf guard
447
444
`nullHero.firstName` never has a chance to fail -->
448
445
< div *ngIf ="nullHero != null "> Hello, {{nullHero.firstName}}</ div >
449
446
@@ -487,33 +484,33 @@ <h3>Use setStyles() - CSS property names</h3>
487
484
</ fieldset >
488
485
489
486
< 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 ">
495
492
<!-- #enddocregion NgSwitch -->
496
493
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 >
512
509
513
510
<!-- #docregion NgSwitch -->
514
- </ span >
515
- <!-- #enddocregion NgSwitch, NgSwitch-expanded -->
516
- </ div >
511
+ </ span >
512
+ <!-- #enddocregion NgSwitch, NgSwitch-expanded -->
513
+ </ div >
517
514
</ div >
518
515
519
516
< a class ="to-toc " href ="#toc "> top</ a >
@@ -620,7 +617,7 @@ <h3>*ngIf expansion</h3>
620
617
< p > < i > expand to <template></ i > </ p >
621
618
<!-- #docregion Template-2 -->
622
619
< template [ngIf] ="currentHero != null ">
623
- < hero-detail [hero] ="currentHero "> </ hero-detail >
620
+ < hero-detail [hero] ="currentHero "> </ hero-detail >
624
621
</ template >
625
622
<!-- #enddocregion Template-2 -->
626
623
@@ -644,15 +641,15 @@ <h3>*ngFor expansion</h3>
644
641
<!-- ngFor w/ hero-detail Component inside a template element -->
645
642
<!-- #docregion Template-4 -->
646
643
< template ngFor let-hero [ngForOf] ="heroes " [ngForTrackBy] ="trackByHeroes ">
647
- < hero-detail [hero] ="hero "> </ hero-detail >
644
+ < hero-detail [hero] ="hero "> </ hero-detail >
648
645
</ template >
649
646
<!-- #enddocregion Template-4 -->
650
647
</ div >
651
648
652
649
< a class ="to-toc " href ="#toc "> top</ a >
653
650
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 >
656
653
657
654
<!-- #docregion ref-phone -->
658
655
<!-- phone refers to the input element; pass its `value` to an event handler -->
@@ -672,7 +669,7 @@ <h4>Example Form</h4>
672
669
< div class ="form-group ">
673
670
< label for ="name "> Name</ label >
674
671
< input class ="form-control " required ngControl ="firstName "
675
- [(ngModel)] ="currentHero.firstName ">
672
+ [(ngModel)] ="currentHero.firstName ">
676
673
</ div >
677
674
<!-- #docregion ref-form-a -->
678
675
< button type ="submit " [disabled] ="!theForm.form.valid "> Submit</ button >
@@ -682,7 +679,7 @@ <h4>Example Form</h4>
682
679
< br > < br >
683
680
684
681
<!-- 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 >
686
683
687
684
< a class ="to-toc " href ="#toc "> top</ a >
688
685
@@ -708,13 +705,15 @@ <h4>Example Form</h4>
708
705
< hr > < h2 id ="pipes "> Pipes</ h2 >
709
706
710
707
<!-- #docregion pipes-1 -->
711
- <!-- Force title to uppercase -->
712
- < div > {{ title | uppercase }}</ div >
708
+ < div > Title through uppercase pipe: {{title | uppercase}}</ div >
713
709
<!-- #enddocregion pipes-1 -->
714
710
715
711
<!-- #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 >
718
717
<!-- #enddocregion pipes-2 -->
719
718
720
719
<!-- #docregion pipes-3 -->
@@ -723,16 +722,14 @@ <h4>Example Form</h4>
723
722
<!-- #enddocregion pipes-3 -->
724
723
725
724
<!-- #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 >
729
726
<!-- #enddocregion pipes-json -->
730
727
731
728
< div > Birthdate: {{(currentHero?.birthdate | date:'longDate') | uppercase}}</ div >
732
729
733
730
< div >
734
731
<!-- pipe price to USD and display the $ symbol -->
735
- < label > Price: </ label > {{product['price'] | currency:'$' }}
732
+ < label > Price: </ label > {{product['price'] | currency:'USD':false }}
736
733
</ div >
737
734
738
735
< a class ="to-toc " href ="#toc "> top</ a >
@@ -742,7 +739,7 @@ <h4>Example Form</h4>
742
739
743
740
< div >
744
741
<!-- #docregion safe-1 -->
745
- The title is {{ title }}
742
+ The title is {{title}}
746
743
<!-- #enddocregion safe-1 -->
747
744
</ div >
748
745
@@ -759,11 +756,10 @@ <h4>Example Form</h4>
759
756
</ div >
760
757
761
758
762
-
763
759
<!--
764
760
The null hero's name is {{nullHero.firstName}}
765
761
766
- See console log:
762
+ See console log:
767
763
EXCEPTION: The null object does not have a getter 'firstName'.
768
764
-->
769
765
@@ -784,19 +780,16 @@ <h4>Example Form</h4>
784
780
785
781
< a class ="to-toc " href ="#toc "> top</ a >
786
782
787
- <!-- Todo : discuss this in the Style binding section -->
783
+ <!-- TODO : discuss this in the Style binding section -->
788
784
<!-- enums in bindings -->
789
-
790
785
< hr > < h2 id ="enums "> Enums in binding</ h2 >
791
786
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 >
801
794
802
795
< a class ="to-toc " href ="#toc "> top</ a >
0 commit comments