Skip to content

Commit 252dd5f

Browse files
wKozawardbell
authored andcommitted
docs(structural-directives): <template> was replaced by <ng-template> (angular#3445)
1 parent 69294a2 commit 252dd5f

File tree

5 files changed

+46
-46
lines changed

5 files changed

+46
-46
lines changed

public/docs/_examples/structural-directives/ts/src/app/app.component.html

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ <h2 id="ngIf">NgIf</h2>
4848
<!-- #enddocregion display-none -->
4949

5050
<h4>NgIf with template</h4>
51-
<p>&lt;template&gt; element</p>
51+
<p>&lt;ng-template&gt; element</p>
5252
<!-- #docregion ngif-template -->
53-
<template [ngIf]="hero">
53+
<ng-template [ngIf]="hero">
5454
<div>{{hero.name}}</div>
55-
</template>
55+
</ng-template>
5656
<!-- #enddocregion ngif-template -->
5757

5858
<p>template attribute</p>
@@ -140,9 +140,9 @@ <h2 id="ngFor">NgFor</h2>
140140
<!--#enddocregion inside-ngfor -->
141141
<p class="code">&lt;template ngFor let-hero [ngForOf]="heroes" let-i="index" let-odd="odd" [ngForTrackBy]="trackById"&gt;</p>
142142
<!--#docregion inside-ngfor -->
143-
<template ngFor let-hero [ngForOf]="heroes" let-i="index" let-odd="odd" [ngForTrackBy]="trackById">
143+
<ng-template ngFor let-hero [ngForOf]="heroes" let-i="index" let-odd="odd" [ngForTrackBy]="trackById">
144144
<div [class.odd]="odd">({{i}}) {{hero.name}}</div>
145-
</template>
145+
</ng-template>
146146
<!--#enddocregion inside-ngfor -->
147147

148148
</div>
@@ -179,21 +179,21 @@ <h4>NgSwitch with <i>template</i> attribute</h4>
179179
</div>
180180
<!-- #enddocregion ngswitch-template-attr -->
181181

182-
<h4>NgSwitch with &lt;template&gt;</h4>
182+
<h4>NgSwitch with &lt;ng-template&gt;</h4>
183183
<!-- #docregion ngswitch-template -->
184184
<div [ngSwitch]="hero?.emotion">
185-
<template [ngSwitchCase]="'happy'">
185+
<ng-template [ngSwitchCase]="'happy'">
186186
<happy-hero [hero]="hero"></happy-hero>
187-
</template>
188-
<template [ngSwitchCase]="'sad'">
187+
</ng-template>
188+
<ng-template [ngSwitchCase]="'sad'">
189189
<sad-hero [hero]="hero"></sad-hero>
190-
</template>
191-
<template [ngSwitchCase]="'confused'">
190+
</ng-template>
191+
<ng-template [ngSwitchCase]="'confused'">
192192
<confused-hero [hero]="hero"></confused-hero>
193-
</template >
194-
<template ngSwitchDefault>
193+
</ng-template >
194+
<ng-template ngSwitchDefault>
195195
<unknown-hero [hero]="hero"></unknown-hero>
196-
</template>
196+
</ng-template>
197197
</div>
198198
<!-- #enddocregion ngswitch-template -->
199199

@@ -202,9 +202,9 @@ <h4>NgSwitch with &lt;template&gt;</h4>
202202
<h2>&lt;template&gt;</h2>
203203
<!-- #docregion template-tag -->
204204
<p>Hip!</p>
205-
<template>
205+
<ng-template>
206206
<p>Hip!</p>
207-
</template>
207+
</ng-template>
208208
<p>Hooray!</p>
209209
<!-- #enddocregion template-tag -->
210210

@@ -242,9 +242,9 @@ <h4>UnlessDirective with template</h4>
242242
(A) &lt;p template="myUnless condition" class="code unless"&gt;
243243
</p>
244244

245-
<template [myUnless]="condition">
245+
<ng-template [myUnless]="condition">
246246
<p class="code unless">
247247
(A) &lt;template [myUnless]="condition"&gt;
248248
</p>
249-
</template>
249+
</ng-template>
250250

public/docs/_examples/template-syntax/ts/src/app/app.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,13 @@ <h3>[ngStyle] binding to currentStyles - CSS property names</h3>
544544

545545
<!-- NgIf binding with template (no *) -->
546546

547-
<template [ngIf]="currentHero">Add {{currentHero.name}} with template</template>
547+
<ng-template [ngIf]="currentHero">Add {{currentHero.name}} with template</ng-template>
548548

549549
<!-- Does not show because isActive is false! -->
550550
<div>Hero Detail removed from DOM (via template) because isActive is false</div>
551-
<template [ngIf]="isActive">
551+
<ng-template [ngIf]="isActive">
552552
<hero-detail></hero-detail>
553-
</template>
553+
</ng-template>
554554

555555
<!-- #docregion NgIf-3 -->
556556
<!-- isSpecial is true -->

public/docs/ts/latest/guide/structural-directives.jade

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ style.
2323

2424
* [Inside the *NgSwitch* directives](#ngSwitch)
2525
* [Prefer the (*) prefix](#prefer-asterisk)
26-
* [The &lt;template> element](#template)
26+
* [The &lt;ng-template> element](#template)
2727
* [Group sibling elements with &lt;ng-container&gt;](#ng-container)
2828
* [Write a structural directive](#unless)
2929

30+
3031
Try the <live-example></live-example>.
3132

3233
a#definition
@@ -52,7 +53,7 @@ a#definition
5253
You'll learn in this guide that the [asterisk (*) is a convenience notation](#asterisk)
5354
and the string is a [_microsyntax_](#microsyntax) rather than the usual
5455
[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
5657
host element and its descendents.
5758
Each structural directive does something different with that template.
5859

@@ -116,7 +117,7 @@ figure.image-display
116117

117118
:marked
118119
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)).
120121

121122
When the condition is false, `NgIf` removes its host element from the DOM,
122123
detaches it from DOM events (the attachments that it made),
@@ -179,13 +180,13 @@ a#asterisk
179180
+makeExcerpt('src/app/app.component.html', 'ngif-template-attr', '')
180181

181182
: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.
183184

184185
+makeExcerpt('src/app/app.component.html', 'ngif-template', '')
185186

186187
: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.
189190

190191
None of these forms are actually rendered.
191192
Only the finished product ends up in the DOM.
@@ -194,8 +195,8 @@ figure.image-display
194195
img(src='/resources/images/devguide/structural-directives/hero-div-in-dom.png' alt="hero div in DOM")
195196

196197
: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.
199200

200201
The [`NgFor`](#ngFor) and [`NgSwitch...`](#ngSwitch) directives follow the same pattern.
201202

@@ -205,7 +206,7 @@ a#ngFor
205206
## Inside _*ngFor_
206207

207208
Angular transforms the `*ngFor` in similar fashion from asterisk (*) syntax through
208-
template _attribute_ to template _element_.
209+
template _attribute_ to `<ng-template>` _element_.
209210

210211
Here's a full-featured application of `NgFor`, written all three ways:
211212

@@ -221,15 +222,15 @@ a#ngFor
221222
.alert.is-helpful
222223
:marked
223224
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>`.
225226
In this example, the `[ngClass]="odd"` stays on the `<div>`.
226227

227228
a#microsyntax
228229
:marked
229230
### Microsyntax
230231

231232
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>`:
233234

234235
* The `let` keyword declares a [_template input variable_](#template-input-variable)
235236
that you reference within the template. The input variables in this example are `hero`, `i`, and `odd`.
@@ -337,7 +338,7 @@ a#ngSwitch
337338
+makeExcerpt('src/app/app.component.html', 'ngswitch-template-attr', '')
338339

339340
: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.
341342

342343
+makeExcerpt('src/app/app.component.html', 'ngswitch-template', '')
343344

@@ -350,20 +351,19 @@ a#prefer-asterisk
350351
to host the directive.
351352

352353
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).
355356

356357
a#template
357358
.l-main-section
358359
:marked
359-
## The *&lt;template&gt;*
360+
## The *&lt;ng-template&gt;*
360361

361-
The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template" target="_blank" title="MDN: Template Tag">HTML 5 &lt;template&gt;</a>
362-
is a formula for rendering HTML.
362+
The &lt;ng-template&gt; is an Angular element for rendering HTML.
363363
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.
365365

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>`,
367367
those elements disappear.
368368
That's the fate of the middle "Hip!" in the phrase "Hip! Hip! Hooray!".
369369

@@ -376,7 +376,7 @@ figure.image-display
376376
img(src='/resources/images/devguide/structural-directives/template-rendering.png' width="350" alt="template tag rendering")
377377

378378
:marked
379-
A structural directive puts a `<template>` to work
379+
A structural directive puts a `<ng-template>` to work
380380
as you'll see when you [write your own structural directive](#unless).
381381

382382
a#ngcontainer
@@ -526,11 +526,11 @@ a#unless
526526

527527
A simple structural directive like this one creates an
528528
[_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
530530
[_view container_](../api/core/index/ViewContainerRef-class.html "API: ViewContainerRef")
531531
adjacent to the directive's original `<p>` host element.
532532

533-
You'll acquire the `<template>` contents with a
533+
You'll acquire the `<ng-template>` contents with a
534534
[`TemplateRef`](../api/core/index/TemplateRef-class.html "API: TemplateRef")
535535
and access the _view container_ through a
536536
[`ViewContainerRef`](../api/core/index/ViewContainerRef-class.html "API: ViewContainerRef").
@@ -614,7 +614,7 @@ a#summary
614614

615615
* that structural directives manipulate HTML layout.
616616
* 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>`.
618618
* 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).
620620
* to write a [custom structural directive](#unless), `UnlessDirective`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ a#microsyntax
14021402
> *Take each hero in the `heroes` array, store it in the local `hero` looping variable, and
14031403
make it available to the templated HTML for each iteration.*
14041404

1405-
Angular translates this instruction into a `<template>` around the host element,
1405+
Angular translates this instruction into a `<ng-template>` around the host element,
14061406
then uses this template repeatedly to create a new set of elements and bindings for each `hero`
14071407
in the list.
14081408

Loading

0 commit comments

Comments
 (0)