Skip to content

Commit 78007cf

Browse files
ng20 update (#25)
1 parent df8a959 commit 78007cf

File tree

1 file changed

+15
-16
lines changed
  • blog/2024-11-effect-afterrendereffect

1 file changed

+15
-16
lines changed

blog/2024-11-effect-afterrendereffect/README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: 'Angular 19: Mastering effect and afterRenderEffect'
2+
title: 'Reactive Angular: Mastering effect and afterRenderEffect'
33
author: Johannes Hoppe
44
55
published: 2024-11-14
6-
lastModified: 2024-11-17
6+
lastModified: 2025-06-17
77
keywords:
88
- Angular
99
- JavaScript
@@ -12,6 +12,7 @@ keywords:
1212
- Effect
1313
- afterRenderEffect
1414
- Angular 19
15+
- Angular 20
1516
language: en
1617
header: effect.jpg
1718
sticky: false
@@ -148,9 +149,11 @@ Here is our example of a form that can create a new book and edit an existing bo
148149
<label for="description">Description</label>
149150
<textarea id="description" [formControl]="c.description"></textarea>
150151
151-
<button type="submit" aria-label="Submit Form">
152-
{{ isEditMode() ? 'Edit Book' : 'Create Book' }}
152+
@let formLabel = isEditMode() ? 'Edit Book' : 'Create Book';
153+
<button type="submit" [attr.aria-label]="formLabel">
154+
{{ formLabel }}
153155
</button>
156+
154157
</form>
155158
`,
156159
})
@@ -224,12 +227,11 @@ like measuring element dimensions, directly managing animations, or orchestratin
224227
The new `afterRenderEffect()` function allows us to control when specific tasks are executed during the DOM update process.
225228
The API itself mirrors the functionality of
226229
* [`afterRender`](https://next.angular.dev/api/core/afterRender) *(registers a callback to be invoked each time the application finishes rendering)* and
227-
* [`afterNextRender`](https://next.angular.dev/api/core/afterNextRender) *(registers callbacks to be invoked the next time the application finishes rendering, during the specified phases.)*
228-
229-
which are both in **Developer Preview**!
230+
* afterNextRender *(registers callbacks to be invoked the next time the application finishes rendering, during the specified phases.)*
230231

231-
The Angular documentation recommends avoiding `afterRender` when possible and suggest specifying explicit phases with `afterNextRender` to avoid significant performance degradation.
232-
You'll see a similar recommendation for `afterRenderEffect()`. There is one signature that is intended for use and another that exists but is not recommended.
232+
The `afterRender` function no longer exists since Angular 20.
233+
Even before that, the documentation recommended specifying explicit phases with `afterNextRender` to avoid significant performance losses.
234+
There is a similar recommendation for `afterRenderEffect()`: There is one signature that is intended for use and another that exists but is not recommended.
233235

234236
However, there is one big difference between the hook methods and the new `afterRenderEffect()`:
235237
> **💡 Values are propagated from phase to phase as signals instead of as plain values.**
@@ -516,13 +518,10 @@ Last but not least, the third link provides an interactive demo on StackBlitz, w
516518

517519
## Conclusion
518520

519-
Angular's new `effect()` API opens up new possibilities for reactive state management and `afterRenderEffect()` provides efficient DOM manipulation when needed.
520-
By understanding when to use each API, developers can create responsive and powerful Angular applications with a clean new syntax.
521-
522-
> **⚠️ Please note that both APIs are in Developer Preview and may still be subject to change!**
523-
524-
But time flies by anyway.
525-
Why not try `effect()` and `afterRenderEffect()` in your Angular project today and see how they simplify your state management and DOM interactions, it certainly will not take much time until the APIs are stable!
521+
Both APIs open up new, elegant ways of state and DOM management in Angular: reactive, precise and clear.
522+
Those who familiarise themselves with `effect()` and `afterRenderEffect()` at an early stage will benefit today from the architecture of tomorrow.
523+
Take the opportunity to try out the new interfaces in your application!
524+
The functions have been considered **stable** since Angular 20.
526525

527526

528527
<hr>

0 commit comments

Comments
 (0)