@@ -23,10 +23,11 @@ style.
23
23
24
24
* [Inside the *NgSwitch* directives](#ngSwitch)
25
25
* [Prefer the (*) prefix](#prefer-asterisk)
26
- * [The <template> element](#template)
26
+ * [The <ng- template> element](#template)
27
27
* [Group sibling elements with <ng-container>](#ng-container)
28
28
* [Write a structural directive](#unless)
29
29
30
+
30
31
Try the <live-example></live-example>.
31
32
32
33
a#definition
@@ -52,7 +53,7 @@ a#definition
52
53
You'll learn in this guide that the [asterisk (*) is a convenience notation](#asterisk)
53
54
and the string is a [_microsyntax_](#microsyntax) rather than the usual
54
55
[template expression](template-syntax.html#template-expressions).
55
- Angular desugars this notation into a marked-up `<template>` that surrounds the
56
+ Angular desugars this notation into a marked-up `<ng- template>` that surrounds the
56
57
host element and its descendents.
57
58
Each structural directive does something different with that template.
58
59
@@ -116,7 +117,7 @@ figure.image-display
116
117
117
118
:marked
118
119
The top paragraph is in the DOM. The bottom, disused paragraph is not;
119
- in its place is a comment about "template bindings" (more about that [later](#asterisk)).
120
+ in its place is a comment about "bindings" (more about that [later](#asterisk)).
120
121
121
122
When the condition is false, `NgIf` removes its host element from the DOM,
122
123
detaches it from DOM events (the attachments that it made),
@@ -179,13 +180,13 @@ a#asterisk
179
180
+ makeExcerpt('src/app/app.component.html' , 'ngif-template-attr' , '' )
180
181
181
182
:marked
182
- Then it translates the template _attribute_ into a template _element_, wrapped around the host element, like this.
183
+ Then it translates the template _attribute_ into a `<ng- template>` _element_, wrapped around the host element, like this.
183
184
184
185
+ makeExcerpt('src/app/app.component.html' , 'ngif-template' , '' )
185
186
186
187
:marked
187
- * The `*ngIf` directive moved to the `<template>` element where it became a property binding,`[ngIf]`.
188
- * The rest of the `<div>`, including its class attribute, moved inside the `<template>` element.
188
+ * The `*ngIf` directive moved to the `<ng- template>` element where it became a property binding,`[ngIf]`.
189
+ * The rest of the `<div>`, including its class attribute, moved inside the `<ng- template>` element.
189
190
190
191
None of these forms are actually rendered.
191
192
Only the finished product ends up in the DOM.
@@ -194,8 +195,8 @@ figure.image-display
194
195
img( src ='/resources/images/devguide/structural-directives/hero-div-in-dom.png' alt ="hero div in DOM" )
195
196
196
197
:marked
197
- Angular consumed the `<template>` content during its actual rendering and
198
- replaced the `<template>` with a diagnostic comment.
198
+ Angular consumed the `<ng- template>` content during its actual rendering and
199
+ replaced the `<ng- template>` with a diagnostic comment.
199
200
200
201
The [`NgFor`](#ngFor) and [`NgSwitch...`](#ngSwitch) directives follow the same pattern.
201
202
@@ -205,7 +206,7 @@ a#ngFor
205
206
## Inside _*ngFor_
206
207
207
208
Angular transforms the `*ngFor` in similar fashion from asterisk (*) syntax through
208
- template _attribute_ to template _element_.
209
+ template _attribute_ to `<ng- template>` _element_.
209
210
210
211
Here's a full-featured application of `NgFor`, written all three ways:
211
212
@@ -221,15 +222,15 @@ a#ngFor
221
222
.alert.is-helpful
222
223
:marked
223
224
Everything _outside_ the `ngFor` string stays with the host element
224
- (the `<div>`) as it moves inside the `<template>`.
225
+ (the `<div>`) as it moves inside the `<ng- template>`.
225
226
In this example, the `[ngClass]="odd"` stays on the `<div>`.
226
227
227
228
a#microsyntax
228
229
:marked
229
230
### Microsyntax
230
231
231
232
The Angular microsyntax lets you configure a directive in a compact, friendly string.
232
- The microsyntax parser translates that string into attributes on the `<template>`:
233
+ The microsyntax parser translates that string into attributes on the `<ng- template>`:
233
234
234
235
* The `let` keyword declares a [_template input variable_](#template-input-variable)
235
236
that you reference within the template. The input variables in this example are `hero`, `i`, and `odd`.
@@ -337,7 +338,7 @@ a#ngSwitch
337
338
+ makeExcerpt('src/app/app.component.html' , 'ngswitch-template-attr' , '' )
338
339
339
340
:marked
340
- That, in turn, can be desugared into the `<template>` element form.
341
+ That, in turn, can be desugared into the `<ng- template>` element form.
341
342
342
343
+ makeExcerpt('src/app/app.component.html' , 'ngswitch-template' , '' )
343
344
@@ -350,20 +351,19 @@ a#prefer-asterisk
350
351
to host the directive.
351
352
352
353
While there's rarely a good reason to apply a structural directive in template _attribute_ or _element_ form,
353
- it's still important to know that Angular creates a `<template>` and to understand how it works.
354
- You'll refer to the `<template>` when you [write your own structural directive](#unless).
354
+ it's still important to know that Angular creates a `<ng- template>` and to understand how it works.
355
+ You'll refer to the `<ng- template>` when you [write your own structural directive](#unless).
355
356
356
357
a#template
357
358
.l-main-section
358
359
:marked
359
- ## The *<template>*
360
+ ## The *<ng- template>*
360
361
361
- The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template" target="_blank" title="MDN: Template Tag">HTML 5 <template></a>
362
- is a formula for rendering HTML.
362
+ The <ng-template> is an Angular element for rendering HTML.
363
363
It is never displayed directly.
364
- In fact, before rendering the view, Angular _replaces_ the `<template>` and its contents with a comment.
364
+ In fact, before rendering the view, Angular _replaces_ the `<ng- template>` and its contents with a comment.
365
365
366
- If there is no structural directive and you merely wrap some elements in a `<template>`,
366
+ If there is no structural directive and you merely wrap some elements in a `<ng- template>`,
367
367
those elements disappear.
368
368
That's the fate of the middle "Hip!" in the phrase "Hip! Hip! Hooray!".
369
369
@@ -376,7 +376,7 @@ figure.image-display
376
376
img( src ='/resources/images/devguide/structural-directives/template-rendering.png' width ="350" alt ="template tag rendering" )
377
377
378
378
:marked
379
- A structural directive puts a `<template>` to work
379
+ A structural directive puts a `<ng- template>` to work
380
380
as you'll see when you [write your own structural directive](#unless).
381
381
382
382
a#ngcontainer
@@ -526,11 +526,11 @@ a#unless
526
526
527
527
A simple structural directive like this one creates an
528
528
[_embedded view_](../api/core/index/EmbeddedViewRef-class.html "API: EmbeddedViewRef")
529
- from the Angular-generated `<template>` and inserts that view in a
529
+ from the Angular-generated `<ng- template>` and inserts that view in a
530
530
[_view container_](../api/core/index/ViewContainerRef-class.html "API: ViewContainerRef")
531
531
adjacent to the directive's original `<p>` host element.
532
532
533
- You'll acquire the `<template>` contents with a
533
+ You'll acquire the `<ng- template>` contents with a
534
534
[`TemplateRef`](../api/core/index/TemplateRef-class.html "API: TemplateRef")
535
535
and access the _view container_ through a
536
536
[`ViewContainerRef`](../api/core/index/ViewContainerRef-class.html "API: ViewContainerRef").
@@ -614,7 +614,7 @@ a#summary
614
614
615
615
* that structural directives manipulate HTML layout.
616
616
* to use [`<ng-container>`](#ngcontainer) as a grouping element when there is no suitable host element.
617
- * that the Angular desugars [asterisk (*) syntax](#asterisk) into a `<template>`.
617
+ * that the Angular desugars [asterisk (*) syntax](#asterisk) into a `<ng- template>`.
618
618
* how that works for the `NgIf`, `NgFor` and `NgSwitch` built-in directives.
619
- * about the [_microsyntax_](#microsyntax) that expands into a [`<template>`](#template).
619
+ * about the [_microsyntax_](#microsyntax) that expands into a [`<ng- template>`](#template).
620
620
* to write a [custom structural directive](#unless), `UnlessDirective`.
0 commit comments