Skip to content

Commit c5b3f1c

Browse files
thePunderWomanalxhub
authored andcommitted
docs: update peek-a-boo example (angular#47219)
The peek-a-boo example image does not exactly reflect what happens. This updates the hook table and the image of the peek-a-boo output. Closes angular#40138 PR Close angular#47219
1 parent b343201 commit c5b3f1c

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

aio/content/guide/lifecycle-hooks.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Use them to perform the following kinds of operations.
4040

4141
| Hook method | Purpose | Timing |
4242
|:--- |:--- |:--- |
43-
| `ngOnChanges()` | Respond when Angular sets or resets data-bound input properties. The method receives a `SimpleChanges` object of current and previous property values. <br /> <div class="alert is-helpful"> **NOTE**: <br /> This happens very frequently, so any operation you perform here impacts performance significantly. </div> See details in [Using change detection hooks](#onchanges) in this document. | Called before `ngOnInit()` \(if the component has bound inputs\) and whenever one or more data-bound input properties change. <br /> <div class="alert is-helpful"> **NOTE**: <br /> If your component has no inputs or you use it without providing any inputs, the framework will not call `ngOnChanges()`. </div> |
43+
| `ngOnChanges()` | Respond when Angular sets or resets data-bound input properties. The method receives a `SimpleChanges` object of current and previous property values. <br /> <div class="alert is-helpful"> **NOTE**: <br /> This happens frequently, so any operation you perform here impacts performance significantly. </div> See details in [Using change detection hooks](#onchanges) in this document. | Called before `ngOnInit()` \(if the component has bound inputs\) and whenever one or more data-bound input properties change. <br /> <div class="alert is-helpful"> **NOTE**: <br /> If your component has no inputs or you use it without providing any inputs, the framework will not call `ngOnChanges()`. </div> |
4444
| `ngOnInit()` | Initialize the directive or component after Angular first displays the data-bound properties and sets the directive or component's input properties. See details in [Initializing a component or directive](#oninit) in this document. | Called once, after the first `ngOnChanges()`. `ngOnInit()` is still called even when `ngOnChanges()` is not \(which is the case when there are no template-bound inputs\). |
4545
| `ngDoCheck()` | Detect and act upon changes that Angular can't or won't detect on its own. See details and example in [Defining custom change detection](#docheck) in this document. | Called immediately after `ngOnChanges()` on every change detection run, and immediately after `ngOnInit()` on the first run. |
4646
| `ngAfterContentInit()` | Respond after Angular projects external content into the component's view, or into the view that a directive is in. <br /> See details and example in [Responding to changes in content](#aftercontent) in this document. | Called *once* after the first `ngDoCheck()`. |
@@ -121,12 +121,16 @@ The sequence of log messages follows the prescribed hook calling order:
121121
|:--- |:--- |
122122
| 1 | `OnChanges` |
123123
| 2 | `OnInit` |
124-
| 3-5 | `DoCheck` |
125-
| 6 | `AfterContentInit` |
126-
| 7-9 | `AfterContentChecked` |
127-
| 10 | `AfterViewInit` |
128-
| 11-13 | `AfterViewChecked` |
129-
| 14 | `OnDestroy` |
124+
| 3 | `DoCheck` |
125+
| 4 | `AfterContentInit` |
126+
| 5 | `AfterContentChecked` |
127+
| 6 | `AfterViewInit` |
128+
| 7 | `AfterViewChecked` |
129+
| 8 | `DoCheck` |
130+
| 9 | `AfterContentChecked` |
131+
| 10 | `AfterViewChecked` |
132+
| 11 | `OnDestroy` |
133+
130134

131135
<div class="alert is-helpful">
132136

@@ -151,8 +155,8 @@ The example does not perform any initialization or clean-up.
151155
It just tracks the appearance and disappearance of an element in the view by recording when the directive itself is instantiated and destroyed.
152156

153157
A spy directive like this can provide insight into a DOM object that you cannot change directly.
154-
You can't touch the implementation of a built-in `<div>`, or modify a third party component.
155-
You can, however watch these elements with a directive.
158+
You can't access the implementation of a built-in `<div>`, or modify a third party component.
159+
You do have the option to watch these elements with a directive.
156160

157161
The directive defines `ngOnInit()` and `ngOnDestroy()` hooks
158162
that log messages to the parent using an injected `LoggerService`.
@@ -253,8 +257,8 @@ The `LoggerService.tick_then()` statement postpones the log update for one turn
253257

254258
#### Write lean hook methods to avoid performance problems
255259

256-
When you run the *AfterView* sample, notice how frequently Angular calls `AfterViewChecked()`-often when there are no changes of interest.
257-
Be very careful about how much logic or computation you put into one of these methods.
260+
When you run the *AfterView* sample, notice how frequently Angular calls `AfterViewChecked()` - often when there are no changes of interest.
261+
Be careful about how much logic or computation you put into one of these methods.
258262

259263
<div class="lightbox">
260264

@@ -284,7 +288,7 @@ AngularJS developers know this technique as *transclusion*.
284288
The *AfterContent* sample explores the `AfterContentInit()` and `AfterContentChecked()` hooks that Angular calls *after* Angular projects external content into the component.
285289

286290
Consider this variation on the [previous *AfterView*](#afterview) example.
287-
This time, instead of including the child view within the template, it imports the content from the `AfterContentComponent`'s parent.
291+
This time, instead of including the child view within the template, it imports the content from the `AfterContentComponent` hook's parent.
288292
The following is the parent's template.
289293

290294
<code-example header="AfterContentParentComponent (template excerpt)" path="lifecycle-hooks/src/app/after-content-parent.component.ts" region="parent-template"></code-example>
@@ -354,7 +358,7 @@ The results are illuminating.
354358

355359
</div>
356360

357-
While the `ngDoCheck()` hook can detect when the hero's `name` has changed, it is very expensive.
361+
While the `ngDoCheck()` hook can detect when the hero's `name` has changed, it is an expensive hook.
358362
This hook is called with enormous frequency &mdash;after *every* change detection cycle no matter where the change occurred.
359363
It's called over twenty times in this example before the user can do anything.
360364

18.2 KB
Loading

0 commit comments

Comments
 (0)