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

Commit bdaf663

Browse files
docs(template-syntax): finish pass on template-syntax.jade
1 parent 5a2703f commit bdaf663

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

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

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ style.
1414

1515
:marked
1616
The Angular application manages what the user sees and can do, achieving this through the interaction of a
17-
Component class instance (the *component*) and its user-facing template.
17+
component class instance (the *component*) and its user-facing template.
1818

1919
You may be familiar with the component/template duality from your experience with model-view-controller (MVC) or model-view-viewmodel (MVVM).
2020
In Angular, the component plays the part of the controller/viewmodel, and the template represents the view.
@@ -76,7 +76,7 @@ code-example(language="html" escape="html").
7676
You can extend the HTML vocabulary of your templates with components and directives that appear as new elements and attributes.
7777
In the following sections, you'll learn how to get and set DOM (Document Object Model) values dynamically through data binding.
7878

79-
Begin with the first form of data binding — interpolation — to see how much richer template HTML can be.
79+
Begin with the first form of data binding—interpolation—to see how much richer template HTML can be.
8080

8181
a(href="#toc") back to top
8282

@@ -147,6 +147,12 @@ block notable-differences
147147

148148
h3#expression-context Expression context
149149

150+
.alert.is-critical
151+
:marked
152+
Ward: you wanted to have a note here per our slack conversation where you said,
153+
"The context for terms in an expression is a blend of the data-bound component
154+
and the directive's context (if it has one). The latter wins when the term is a property of both."
155+
150156
:marked
151157
The *expression context* is typically the component instance.
152158
In the following examples, the *title* within double-curly braces, `{{title}}` is a property of the data-bound component.
@@ -381,7 +387,7 @@ table(width="100%")
381387
+makeExample('template-syntax/ts/app/app.component.html', 'disabled-button-1')(format=".")
382388
:marked
383389
You'll get to that peculiar bracket notation in a moment. Looking beyond it,
384-
your intuition suggest that you're binding to the button's `disabled` attribute and setting
390+
your intuition suggests that you're binding to the button's `disabled` attribute and setting
385391
it to the current value of the component's `isUnchanged` property.
386392

387393
Your intuition is incorrect! Your everyday HTML mental model is misleading.
@@ -442,7 +448,7 @@ table(width="100%")
442448
When you write a data binding, you're dealing exclusively with properties and events of the target object.
443449
HTML attributes effectively disappear.
444450
:marked
445-
With this model firmly in mind, let's learn about binding targets.
451+
With this model firmly in mind, read on to learn about binding targets.
446452

447453
### Binding targets
448454
The **target of a data binding** is something in the DOM.
@@ -601,7 +607,7 @@ block dart-type-exceptions
601607
:marked
602608
### Remember the brackets
603609
The brackets tell Angular to evaluate the template expression.
604-
If directive forget the brackets, Angular treats the string as a constant and *initializes the target property* with that string.
610+
If you omit the brackets, Angular treats the string as a constant and *initializes the target property* with that string.
605611
It does *not* evaluate the string!
606612

607613
Don't make the following mistake:
@@ -615,7 +621,7 @@ a(id="one-time-initialization")
615621
### One-time string initialization
616622
You *should* omit the brackets when all of the following are true:
617623
* The target property accepts a string value.
618-
* The string is a fixed value that directive can bake into the template.
624+
* The string is a fixed value that you can bake into the template.
619625
* This initial value never changes.
620626

621627
You routinely initialize attributes this way in standard HTML, and it works
@@ -785,7 +791,7 @@ a(href="#toc") back to top
785791
a#event-binding
786792
:marked
787793
## Event binding ( <span class="syntax">(event)</span> )
788-
The bindings directive've met so far flow data in one direction: **from a component to an element**.
794+
The bindings directives you've met so far flow data in one direction: **from a component to an element**.
789795

790796
Users don't just stare at the screen. They enter text into input boxes. They pick items from lists.
791797
They click buttons. Such user actions may result in a flow of data in the opposite direction:
@@ -840,6 +846,12 @@ a#event-binding
840846

841847
Consider this example:
842848
+makeExample('template-syntax/ts/app/app.component.html', 'without-NgModel')(format=".")
849+
850+
.alert.is-critical
851+
:marked
852+
Ward: `firstName` appears here (below) for the first time without any mention it was coming and isn't in the
853+
code sample. Do we mean `name` instead?
854+
843855
:marked
844856
This code sets the input box `value` property by binding to the `firstName` property. To listen for changes to the value, the code binds to the input box's `input` event.
845857
When the user makes changes, the `input` event is raised, and the binding executes the statement within a context that includes the DOM event object, `$event`.
@@ -967,7 +979,7 @@ a#two-way
967979

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

970-
You'd like to use two-way binding with HTML form elements like `<input>` and `<select>`.
982+
It would be convenient to use two-way binding with HTML form elements like `<input>` and `<select>`.
971983
However, no native HTML element follows the `x` value and `xChange` event pattern.
972984

973985
Fortunately, the Angular [_NgModel_](#ngModel) directive is a bridge that enables two-way binding to form elements.
@@ -985,7 +997,7 @@ a#directives
985997

986998
You don't need many of those directives in Angular.
987999
You can often achieve the same results with the more capable and expressive Angular binding system.
988-
Why create a directive to handle a click when directive can write a simple binding such as this?
1000+
Why create a directive to handle a click when you can write a simple binding such as this?
9891001
+makeExample('template-syntax/ts/app/app.component.html', 'event-binding-1')(format=".")
9901002
:marked
9911003
You still benefit from directives that simplify complex tasks.
@@ -1036,7 +1048,7 @@ a#ngClass
10361048
:marked
10371049
Consider a `setCurrentClasses` component method that sets a component property,
10381050
`currentClasses` with an object that adds or removes three classes based on the
1039-
`true`/`false` state of three other component propertes:
1051+
`true`/`false` state of three other component properties:
10401052
+makeExample('template-syntax/ts/app/app.component.ts', 'setClasses')(format=".")
10411053
:marked
10421054
Adding an `ngClass` property binding to `currentClasses` sets the element's classes accordingly:
@@ -1078,7 +1090,8 @@ a(href="#toc") back to top
10781090
a#ngModel
10791091
:marked
10801092
### NgModel - Two-way binding to form elements with <span class="syntax">[(ngModel)]</span>
1081-
When developing data entry forms, directive often both display a data property and update that property when the user makes changes.
1093+
When developing data entry forms, you often both display a data property and
1094+
update that property when the user makes changes.
10821095

10831096
Two-way data binding with the `NgModel` directive makes that easy. Here's an example:
10841097
+makeExcerpt('app/app.component.html', 'NgModel-1', '')
@@ -1088,7 +1101,7 @@ a#ngModel
10881101
#### _FormsModule_ is required to use _ngModel_
10891102

10901103
Before using the `ngModel` directive in a two-way data binding,
1091-
directive must import the `FormsModule` and add it to the Angular module's `imports` list.
1104+
you must import the `FormsModule` and add it to the Angular module's `imports` list.
10921105
Learn more about the `FormsModule` and `ngModel` in the
10931106
[Forms](../guide/forms.html#ngModel) guide.
10941107

@@ -1123,15 +1136,15 @@ a#ngModel
11231136
You can't apply `[(ngModel)]` to a non-form native element or a third-party custom component until you write a suitable *value accessor*,
11241137
a technique that is beyond the scope of this guide.
11251138

1126-
You don't need a _value accessor_ for an Angular component that you write ... because you can name the value and event properties
1139+
You don't need a _value accessor_ for an Angular component that you write because you can name the value and event properties
11271140
to suit Angular's basic [two-way binding syntax](#two-way) and skip `NgModel` altogether.
11281141
The [`sizer` shown above](#two-way) is an example of this technique.
11291142

11301143
:marked
11311144
Separate `ngModel` bindings is an improvement over binding to the element's native properties. You can do better.
11321145

11331146
You shouldn't have to mention the data property twice. Angular should be able to capture the component's data property and set it
1134-
with a single declaration &mdash; which it can with the `[(ngModel)]` syntax:
1147+
with a single declaration, which it can with the `[(ngModel)]` syntax:
11351148
+makeExample('template-syntax/ts/app/app.component.html', 'NgModel-1')(format=".")
11361149
:marked
11371150
Is `[(ngModel)]` all you need? Is there ever a reason to fall back to its expanded form?
@@ -1370,7 +1383,7 @@ figure.image-display
13701383
Each component has a `hero` [input property](#inputs-outputs "Input property")
13711384
which is bound to the `currentHero` of the parent component.
13721385

1373-
Switch directives work as well with native elements and Web Components too.
1386+
Switch directives work as well with native elements and web components too.
13741387
For example, you could replace the `<confused-hero>` switch case with the following.
13751388
+makeExample('template-syntax/ts/app/app.component.html', 'NgSwitch-div')(format=".")
13761389

@@ -1386,7 +1399,7 @@ a#ref-var
13861399
:marked
13871400
A **template reference variable** is often a reference to a DOM element within a template.
13881401
It can also be a reference to an Angular component or directive or a
1389-
<a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components" target="_blank" title="MDN: Web Components">Web Component</a>.
1402+
<a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components" target="_blank" title="MDN: Web Components">web component</a>.
13901403

13911404
Use the hash symbol (#) to declare a reference variable.
13921405
The `#phone` declares a `phone` variable on an `<input>` element.
@@ -1418,7 +1431,7 @@ a#ref-var
14181431
The `heroForm` is actually a reference to an Angular [NgForm](../api/forms/index/NgForm-directive.html "API: NgForm")
14191432
directive with the ability to track the value and validity of every control in the form.
14201433

1421-
The native `<form>` element doesn't have a `form` propery.
1434+
The native `<form>` element doesn't have a `form` property.
14221435
But the `NgForm` directive does, which explains how you can disable the submit button
14231436
if the `heroForm.form.valid` is invalid and pass the entire form control tree
14241437
to the parent component's `onSubmit` method.
@@ -1477,6 +1490,15 @@ a#inputs-outputs
14771490
:marked
14781491
They are *neither inputs nor outputs* of the component. They are data sources for their bindings.
14791492

1493+
.alert.is-critical
1494+
:marked
1495+
Ward: I was momentarily uncertain below because the instructions say to look
1496+
at `HeroDetailComponent` but it doesn't occur explicitly in the code sample.
1497+
In the following paragraph I then see `HeroDetailComponent.hero` and think,
1498+
"hm, ok, I guess that means we're inside `HeroDetailComponent`", but my
1499+
assumption feels wobbly.
1500+
1501+
:marked
14801502
Now look at `HeroDetailComponent` when it is the **target of a binding**.
14811503
+makeExample('template-syntax/ts/app/app.component.html', 'io-2')(format=".")
14821504
:marked

0 commit comments

Comments
 (0)