Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fbfec94

Browse filesBrowse files
dario-piotrowiczatscott
authored andcommitted
docs: amend links in content-projection guide (#43009)
PR Close #43009
1 parent 0e47334 commit fbfec94
Copy full SHA for fbfec94

File tree

Expand file treeCollapse file tree

1 file changed

+28
-28
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-28
lines changed

‎aio/content/guide/content-projection.md

Copy file name to clipboardExpand all lines: aio/content/guide/content-projection.md
+28-28Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,43 @@ The most basic form of content projection is *single-slot content projection*. S
2323

2424
To create a component that uses single-slot content projection:
2525

26-
1. [Create](guide/component-overview) a component.
26+
1. [Create a component](guide/component-overview#creating-a-component).
2727

28-
1. In the template for your component, add an `ng-content` element where you want the projected content to appear.
28+
1. In the template for your component, add an `<ng-content>` element where you want the projected content to appear.
2929

30-
For example, the following component uses an `ng-content` element to display a message.
30+
For example, the following component uses an `<ng-content>` element to display a message.
3131

3232
<code-example path="content-projection/src/app/zippy-basic/zippy-basic.component.ts" header="content-projection/src/app/zippy-basic/zippy-basic.component.ts"></code-example>
3333

34-
With the `ng-content` element in place, users of this component can now project their own message into the component. For example:
34+
With the `<ng-content>` element in place, users of this component can now project their own message into the component. For example:
3535

3636
<code-example path="content-projection/src/app/app.component.html" header="content-projection/src/app/app.component.html"
3737
region="single-slot"></code-example>
3838

3939
<div class="alert is-helpful">
4040

41-
The `ng-content` element is a placeholder that does not create a real DOM element. Custom attributes applied to `ng-content` are ignored.
41+
The `<ng-content>` element is a placeholder that does not create a real DOM element. Custom attributes applied to `<ng-content>` are ignored.
4242

4343
</div>
4444

4545
{@a multi-slot}
4646
## Multi-slot content projection
4747

48-
A component can have multiple slots. Each slot can specify a CSS selector that determines which content goes into that slot. This pattern is referred to as *multi-slot content projection*. With this pattern, you must specify where you want the projected content to appear. You accomplish this task by using the `select` attribute of `ng-content`.
48+
A component can have multiple slots. Each slot can specify a CSS selector that determines which content goes into that slot. This pattern is referred to as *multi-slot content projection*. With this pattern, you must specify where you want the projected content to appear. You accomplish this task by using the `select` attribute of `<ng-content>`.
4949

5050
To create a component that uses multi-slot content projection:
5151

52-
1. [Create](guide/component-overview) a component.
52+
1. [Create a component](guide/component-overview#creating-a-component).
5353

54-
1. In the template for your component, add an `ng-content` element where you want the projected content to appear.
54+
1. In the template for your component, add an `<ng-content>` element where you want the projected content to appear.
5555

56-
1. Add a `select` attribute to the `ng-content` elements. Angular supports [selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) for any combination of tag name, attribute, CSS class, and the `:not` pseudo-class.
56+
1. Add a `select` attribute to the `<ng-content>` elements. Angular supports [selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) for any combination of tag name, attribute, CSS class, and the `:not` pseudo-class.
5757

58-
For example, the following component uses two `ng-content` elements.
58+
For example, the following component uses two `<ng-content>` elements.
5959

6060
<code-example path="content-projection/src/app/zippy-multislot/zippy-multislot.component.ts" header="content-projection/src/app/zippy-multislot/zippy-multislot.component.ts"></code-example>
6161

62-
Content that uses the `question` attribute is projected into the `ng-content` element with the `select=[question]` attribute.
62+
Content that uses the `question` attribute is projected into the `<ng-content>` element with the `select=[question]` attribute.
6363

6464
<code-example path="content-projection/src/app/app.component.html" header="content-projection/src/app/app.component.html"
6565
region="multi-slot"></code-example>
@@ -68,51 +68,51 @@ region="multi-slot"></code-example>
6868

6969
<header>ng-content without a select attribute</header>
7070

71-
If your component includes an `ng-content` element without a `select` attribute, that instance receives all projected components that do not match any of the other `ng-content` elements.
71+
If your component includes an `<ng-content>` element without a `select` attribute, that instance receives all projected components that do not match any of the other `<ng-content>` elements.
7272

73-
In the preceding example, only the second `ng-content` element defines a `select` attribute. As a result, the first `ng-content` element receives any other content projected into the component.
73+
In the preceding example, only the second `<ng-content>` element defines a `select` attribute. As a result, the first `<ng-content>` element receives any other content projected into the component.
7474

7575
</div>
7676

7777
{@a conditional }
7878

7979
## Conditional content projection
8080

81-
If your component needs to _conditionally_ render content, or render content multiple times, you should configure that component to accept an `ng-template` element that contains the content you want to conditionally render.
81+
If your component needs to _conditionally_ render content, or render content multiple times, you should configure that component to accept an `<ng-template>` element that contains the content you want to conditionally render.
8282

83-
Using an `ng-content` element in these cases is not recommended, because when the consumer of a component supplies the content, that content is _always_ initialized, even if the component does not define an `ng-content` element or if that `ng-content` element is inside of an `ngIf` statement.
83+
Using an `<ng-content>` element in these cases is not recommended, because when the consumer of a component supplies the content, that content is _always_ initialized, even if the component does not define an `<ng-content>` element or if that `<ng-content>` element is inside of an `ngIf` statement.
8484

85-
With an `ng-template` element, you can have your component explicitly render content based on any condition you want, as many times as you want. Angular will not initialize the content of an `ng-template` element until that element is explicitly rendered.
85+
With an `<ng-template>` element, you can have your component explicitly render content based on any condition you want, as many times as you want. Angular will not initialize the content of an `<ng-template>` element until that element is explicitly rendered.
8686

87-
The following steps demonstrate a typical implementation of conditional content projection using `ng-template`.
87+
The following steps demonstrate a typical implementation of conditional content projection using `<ng-template>`.
8888

89-
1. [Create](guide/component-overview) a component.
89+
1. [Create a component](guide/component-overview#creating-a-component).
9090

91-
1. In the component that accepts an `ng-template` element, use an `ng-container` element to render that template, such as:
91+
1. In the component that accepts an `<ng-template>` element, use an `<ng-container>` element to render that template, such as:
9292

9393
<code-example path="content-projection/src/app/example-zippy.template.html" header="content-projection/src/app/example-zippy.template.html" region="ng-container">
9494
</code-example>
9595

96-
This example uses the `ngTemplateOutlet` directive to render a given `ng-template` element, which you will define in a later step. You can apply an `ngTemplateOutlet` directive to any type of element. This example assigns the directive to an `ng-container` element because the component does not need to render a real DOM element.
96+
This example uses the `ngTemplateOutlet` directive to render a given `<ng-template>` element, which you will define in a later step. You can apply an `ngTemplateOutlet` directive to any type of element. This example assigns the directive to an `<ng-container>` element because the component does not need to render a real DOM element.
9797

98-
1. Wrap the `ng-container` element in another element, such as a `div` element, and apply your conditional logic.
98+
1. Wrap the `<ng-container>` element in another element, such as a `div` element, and apply your conditional logic.
9999

100100
<code-example path="content-projection/src/app/example-zippy.template.html" header="content-projection/src/app/example-zippy.template.html" region="ngif">
101101
</code-example>
102102

103-
1. In the template where you want to project content, wrap the projected content in an `ng-template` element, such as:
103+
1. In the template where you want to project content, wrap the projected content in an `<ng-template>` element, such as:
104104

105105
<code-example path="content-projection/src/app/app.component.html" region="ng-template">
106106
</code-example>
107107

108-
The `ng-template` element defines a block of content that a component can render based on its own logic. A component can get a reference to this template content, or [`TemplateRef`](/api/core/TemplateRef), by using either the [`@ContentChild`](/api/core/ContentChild) or [`@ContentChildren`](/api/core/ContentChildren) decorators. The preceding example creates a custom directive, `appExampleZippyContent`, as an API to mark the `ng-template` for the component's content. With the `TemplateRef`, the component can render the referenced content by using either the [`ngTemplateOutlet`](/api/common/NgTemplateOutlet) directive, or with [`ViewContainerRef.createEmbeddedView`](/api/core/ViewContainerRef#createembeddedview).
108+
The `<ng-template>` element defines a block of content that a component can render based on its own logic. A component can get a reference to this template content, or `TemplateRef`, by using either the `@ContentChild` or `@ContentChildren` decorators. The preceding example creates a custom directive, `appExampleZippyContent`, as an API to mark the `<ng-template>` for the component's content. With the `TemplateRef`, the component can render the referenced content by using either the `ngTemplateOutlet` directive, or with the `ViewContainerRef` method `createEmbeddedView()`.
109109

110-
1. Create a directive with a selector that matches the custom attribute for your template. In this directive, inject a TemplateRef instance.
110+
1. [Create an attribute directive](guide/attribute-directives#building-an-attribute-directive) with a selector that matches the custom attribute for your template. In this directive, inject a TemplateRef instance.
111111

112112
<code-example path="content-projection/src/app/app.component.ts" header="content-projection/src/app/app.component.ts" region="zippycontentdirective">
113113
</code-example>
114114

115-
In the previous step, you added an `ng-template` element with a custom attribute, `appExampleZippyDirective`. This code provides the logic that Angular will use when it encounters that custom attribute. In this case, that logic instructs Angular to instantiate a template reference.
115+
In the previous step, you added an `<ng-template>` element with a custom attribute, `appExampleZippyDirective`. This code provides the logic that Angular will use when it encounters that custom attribute. In this case, that logic instructs Angular to instantiate a template reference.
116116

117117
1. In the component you want to project content into, use `@ContentChild` to get the template of the projected content.
118118

@@ -144,14 +144,14 @@ For instance, consider the following HTML snippet:
144144
<code-example path="content-projection/src/app/app.component.html" header="content-projection/src/app/app.component.html" region="ngprojectas">
145145
</code-example>
146146

147-
This example uses an `ng-container` attribute to simulate projecting a component into a more complex structure.
147+
This example uses an `<ng-container>` attribute to simulate projecting a component into a more complex structure.
148148

149149
<div class="callout is-helpful">
150150

151151
<header>Reminder!</header>
152152

153-
The `ng-container` element is a logical construct that you can use to group other DOM elements; however, the `ng-container` itself is not rendered in the DOM tree.
153+
The `<ng-container>` element is a logical construct that you can use to group other DOM elements; however, the `<ng-container>` itself is not rendered in the DOM tree.
154154

155155
</div>
156156

157-
In this example, the content we want to project resides inside another element. To project this content as intended, the template uses the `ngProjectAs` attribute. With `ngProjectAs`, the entire `ng-container` element is projected into a component using the `[question]` selector.
157+
In this example, the content we want to project resides inside another element. To project this content as intended, the template uses the `ngProjectAs` attribute. With `ngProjectAs`, the entire `<ng-container>` element is projected into a component using the `[question]` selector.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.