Skip to content

Commit 14f90ea

Browse files
committed
docs: template syntax refresh for style, accuracy, understanding
Move details of structural directives from template-syntax to structural-directives guide/structural-directives Add <ng-container> to structural-directives Touch up glossary Better conformance to google doc guidelines: we->you closes angular#2303, angular#2885
1 parent 35bbeb2 commit 14f90ea

File tree

10 files changed

+461
-228
lines changed

10 files changed

+461
-228
lines changed
Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
<!-- #docplaster -->
22
<!-- #docregion -->
3+
<style>
4+
.syntax { font-family: Consolas, 'Lucida Sans', Courier, sans-serif;}
5+
</style>
36
<h1>Structural Directives</h1>
7+
<h3>Do not confuse &lt;ng-container&gt; with &lt;ng-content&gt; !</h3>
8+
<p>&lt;ng-content&gt;this is an Angular parse error&lt;/ng-content&gt;</p>
9+
<div [style.font-family]="'courier, sans-serif'">Template parse errors:<br>
10+
&lt;ng-content&gt; element cannot have content.</div>
11+
12+
<p [style.maxWidth]="'40em'">
13+
The HTML &lt;template&gt; element is a mechanism for holding client-side content that is
14+
not to be rendered when a page is loaded but may subsequently be instantiated during runtime using JavaScript.
15+
- <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template" target="_blank">MDN on &lt;template&gt;</a>
16+
</p>
17+
<p><b>&lt;template&gt;Inside template&lt;/template&gt;</b> <i>nothing to see</i>:</p>
18+
<template>Inside template</template>
19+
<p><b>&lt;ng-container&gt;Inside ng-container&lt;/ng-container&gt;</b></p>
20+
<ng-container>Inside ng-container</ng-container>
21+
<p><b>&lt;span *ngFor="let hero of heroes"&gt;</b> <i>&lt;span&gt; is repeated</i>:</p>
22+
<span *ngFor="let hero of heroes">{{hero.fullName}} </span>
23+
24+
<p><b>&lt;template *ngFor="let hero of heroes"&gt;</b> <i>nothing to see</i>:</p>
25+
<template *ngFor="let hero of heroes">{{hero.fullName}} </template>
26+
27+
<p><b>&lt;template ngFor let-hero [ngForOf]="heroes"&gt;:</b></p>
28+
<template ngFor let-hero [ngForOf]="heroes">{{hero.fullName}} </template>
29+
30+
<p><b>&lt;ng-container *ngFor="let hero of heroes"&gt;:</b></p>
31+
<ng-container *ngFor="let hero of heroes">{{hero.fullName}} </ng-container>
432

533
<!-- #docregion structural-directives -->
634
<!-- #docregion asterisk -->
@@ -63,17 +91,11 @@ <h4>heavy-loader log:</h4>
6391
<hr>
6492

6593
<!-- #docregion template-tag -->
66-
<p>
67-
Hip!
68-
</p>
94+
<p>Hip!</p>
6995
<template>
70-
<p>
71-
Hip!
72-
</p>
96+
<p>Hip!</p>
7397
</template>
74-
<p>
75-
Hooray!
76-
</p>
98+
<p>Hooray!</p>
7799
<!-- #enddocregion template-tag -->
78100

79101
<hr>
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
// #docplaster
21
// #docregion
32
import { Component } from '@angular/core';
43

54
@Component({
65
moduleId: module.id,
7-
selector: 'structural-directives',
8-
templateUrl: './structural-directives.component.html',
6+
selector: 'my-app',
7+
templateUrl: './app.component.html',
98
styles: ['button { min-width: 100px; }']
109
})
11-
export class StructuralDirectivesComponent {
10+
export class AppComponent {
1211
heroes = ['Mr. Nice', 'Narco', 'Bombasto'];
1312
hero = this.heroes[0];
1413
condition = true;
1514
isVisible = true;
1615
logs: string[] = [];
1716
status = 'ready';
1817
}
19-
// #enddocregion

public/docs/_examples/structural-directives/ts/app/app.module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
import { NgModule } from '@angular/core';
33
import { BrowserModule } from '@angular/platform-browser';
44

5-
import { StructuralDirectivesComponent } from './structural-directives.component';
6-
import { UnlessDirective } from './unless.directive';
5+
import { AppComponent } from './app.component';
6+
import { UnlessDirective } from './unless.directive';
77
import { HeavyLoaderComponent } from './heavy-loader.component';
88

99
@NgModule({
1010
imports: [ BrowserModule ],
1111
declarations: [
12-
StructuralDirectivesComponent,
12+
AppComponent,
1313
UnlessDirective,
1414
HeavyLoaderComponent
1515
],
16-
bootstrap: [ StructuralDirectivesComponent ]
16+
bootstrap: [ AppComponent ]
1717
})
1818
export class AppModule { }

public/docs/_examples/structural-directives/ts/plnkr.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"description": "Structural directives",
3-
"files": ["!**/*.d.ts", "!**/*.js"],
3+
"files": [
4+
"!**/*.d.ts",
5+
"!**/*.js"
6+
],
47
"tags": [
58
"structural", "directives", "template", "ngIf",
69
"ngSwitch", "ngFor"

public/docs/ts/latest/glossary.jade

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ a#aot
5454
:marked
5555
In practice, a synonym for [Decoration](#decorator).
5656

57+
a#attribute-directive
58+
a#attribute-directives
5759
:marked
58-
## Attribute directive
60+
## Attribute directives
5961
.l-sub-section
6062
:marked
6163
A category of [directive](#directive) that can listen to and modify the behavior of
@@ -64,6 +66,8 @@ a#aot
6466

6567
A good example of an attribute directive is the `ngClass` directive for adding and removing CSS class names.
6668

69+
Learn about them in the [_Attribute Directives_](!{docsLatest}/guide/attribute-directives.html) guide.
70+
6771
.l-main-section#B
6872

6973
+ifDocsFor('ts|js')
@@ -141,6 +145,7 @@ a#aot
141145
This form is also known as **lower camel case**, to distinguish it from **upper camel case**, which is [PascalCase](#pascalcase).
142146
When you see "camelCase" in this documentation it always means *lower camel case*.
143147

148+
a#component
144149
:marked
145150
## Component
146151
.l-sub-section
@@ -245,7 +250,7 @@ a#aot
245250
that "B" is a dependency of "A".
246251

247252
You can ask a "dependency injection system" to create "A"
248-
for us and handle all the dependencies.
253+
and it will handle all of "A"s dependencies.
249254
If "A" needs "B" and "B" needs "C", the system resolves that chain of dependencies
250255
and returns a fully prepared instance of "A".
251256

@@ -276,18 +281,20 @@ a#aot
276281
Registering providers is a critical preparatory step.
277282

278283
Angular registers some of its own providers with every injector.
279-
We can register our own providers.
284+
You can register your own providers.
280285

281286
Read more in the [Dependency Injection](!{docsLatest}/guide/dependency-injection.html) page.
287+
288+
a#directive
289+
a#directives
282290
:marked
283291
## Directive
284292
.l-sub-section
285293
:marked
286294
An Angular class responsible for creating, reshaping, and interacting with HTML elements
287295
in the browser DOM. Directives are Angular's most fundamental feature.
288296

289-
A Directive is almost always associated with an HTML element or attribute.
290-
We often refer to such an element or attribute as the directive itself.
297+
A directive is almost always associated with an HTML element or attribute.
291298
When Angular finds a directive in an HTML template,
292299
it creates the matching directive class instance
293300
and gives the instance control over that portion of the browser DOM.
@@ -300,15 +307,15 @@ a#aot
300307
Directives fall into one of three categories:
301308

302309
1. [Components](#component) that combine application logic with an HTML template to
303-
render application [views]. Components are usually represented as HTML elements.
310+
render application [views](#view). Components are usually represented as HTML elements.
304311
They are the building blocks of an Angular application and the
305312
developer can expect to write a lot of them.
306313

307-
1. [Attribute directives](#attribute-directive) that can listen to and modify the behavior of
314+
1. [Attribute directives](#attribute-directives) that can listen to and modify the behavior of
308315
other HTML elements, attributes, properties, and components. They are usually represented
309316
as HTML attributes, hence the name.
310317

311-
1. [Structural directives](#structural-directive), a directive responsible for
318+
1. [Structural directives](#structural-directives), a directive responsible for
312319
shaping or reshaping HTML layout, typically by adding, removing, or manipulating
313320
elements and their children.
314321

@@ -630,21 +637,24 @@ a#snake-case
630637
Applications often require services such as a hero data service or a logging service.
631638

632639
A service is a class with a focused purpose.
633-
We often create a service to implement features that are
640+
You often create a service to implement features that are
634641
independent from any specific view,
635642
provide shared data or logic across components, or encapsulate external interactions.
636643

637644
For more information, see the [Services](!{docsLatest}/tutorial/toh-pt4.html) page of the [Tour of Heroes](!{docsLatest}/tutorial/) tutorial.
638645

646+
a#structural-directive
647+
a#structural-directives
639648
:marked
640-
## Structural directive
649+
## Structural directives
641650
.l-sub-section
642651
:marked
643652
A category of [directive](#directive) that can
644653
shape or reshape HTML layout, typically by adding, removing, or manipulating
645-
elements and their children; for example, the `ngIf` "conditional element" directive and the `ngFor` "repeater" directive.
654+
elements and their children.
655+
Examples include the `*ngIf` _conditional_ directive and the `*ngFor` _repeater_ directive.
646656

647-
Read more in the [Structural Directives](!{docsLatest}/guide/structural-directives.html) page.
657+
Read more in the [_Structural Directives_](!{docsLatest}/guide/structural-directives.html) guide.
648658

649659
.l-main-section#T
650660
:marked
@@ -699,8 +709,8 @@ a#snake-case
699709
A version of JavaScript that supports most [ECMAScript 2015](#es2015)
700710
language features such as [decorators](#decorator).
701711

702-
TypeScript is also noteable for its optional typing system, which gives
703-
us compile-time type checking and strong tooling support (for example, "intellisense",
712+
TypeScript is also noteable for its optional typing system, which enables
713+
compile-time type checking and strong tooling support (for example, "intellisense",
704714
code completion, refactoring, and intelligent search). Many code editors
705715
and IDEs support TypeScript either natively or with plugins.
706716

0 commit comments

Comments
 (0)