@@ -668,9 +668,6 @@ code-example(format="nocode").
668
668
We can replace that with a binding to a string of the desired class names; this is an all-or-nothing, replacement binding.
669
669
+ makeExample('template-syntax/ts/app/app.component.html' , 'class-binding-2' )( format ="." )
670
670
671
- block dart-class-binding-bug
672
- //- N/A
673
-
674
671
:marked
675
672
Finally, we can bind to a specific class name.
676
673
Angular adds the class when the template expression evaluates to #{_truthy}.
@@ -854,35 +851,43 @@ block style-property-name-dart-diff
854
851
Angular offers a special _two-way data binding_ syntax for this purpose, **`[(x)]`**.
855
852
The `[(x)]` syntax combines the brackets
856
853
of _Property Binding_, `[x]`, with the parentheses of _Event Binding_, `(x)`.
854
+
857
855
.callout.is-important
858
856
header [( )] = banana in a box
859
857
:marked
860
858
Visualize a *banana in a box* to remember that the parentheses go _inside_ the brackets.
859
+
861
860
:marked
862
861
The `[(x)]` syntax is easy to demonstrate when the element has a settable property called `x`
863
862
and a corresponding event named `xChange`.
864
- Here's a `SizerComponent ` that fits the pattern.
863
+ Here's a `MySizerComponent ` that fits the pattern.
865
864
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
+
867
868
:marked
868
869
The initial `size` is an input value from a property binding.
869
870
Clicking the buttons increases or decreases the `size`, within min/max values constraints,
870
871
and then raises (_emits_) the `sizeChange` event with the adjusted size.
871
872
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
+
874
877
: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>.
879
882
880
883
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
+
883
888
: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.
886
891
887
892
Clearly the two-way binding syntax is a great convenience compared to separate property and event bindings.
888
893
0 commit comments