{"id":1459,"date":"2023-09-15T05:00:00","date_gmt":"2023-09-15T12:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1459"},"modified":"2023-09-12T15:41:37","modified_gmt":"2023-09-12T22:41:37","slug":"whats-new-in-angular-16-2-lifecycle-methods","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/whats-new-in-angular-16-2-lifecycle-methods\/","title":{"rendered":"What&#8217;s new in Angular 16.2? Lifecycle methods"},"content":{"rendered":"\n<p>Angular keeps evolving at a <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/angular-release-schedule\/\" target=\"_blank\" rel=\"noopener\" title=\"\">steady pace<\/a>, and <a href=\"https:\/\/github.com\/angular\/angular\/releases\/tag\/16.2.0\" target=\"_blank\" rel=\"noopener\" title=\"\">Angular 16.2<\/a> brought a couple of interesting features to the table.<\/p>\n\n\n\n<p>The first feature is an addition to the <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/signals-why-and-when-do-we-need-them\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Signals API<\/a> that was part of a specific <a href=\"https:\/\/github.com\/angular\/angular\/discussions\/49682\" target=\"_blank\" rel=\"noopener\" title=\"\">RFC for Signal-based components<\/a>. The new feature consists of two functions: <\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/angular.io\/api\/core\/afterNextRender\"><code>afterNextRender<\/code><\/a><\/h3>\n\n\n\n<p>A function that allows registering a callback to be invoked the next time the application finishes rendering. It is similar to the <code>ngAfterViewInit<\/code> lifecycle method but for signal-based components.<\/p>\n\n\n\n<p>The main use-case for this new lifecycle is to initialize a third-party, non-Angular-friendly library to hook itself on the DOM after Angular generates it:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"627\" height=\"403\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/09\/image-18.png\" alt=\"\" class=\"wp-image-1460\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/09\/image-18.png 627w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/09\/image-18-300x193.png 300w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/angular.io\/api\/core\/afterRender\">afterRender<\/a><\/h3>\n\n\n\n<p>A function very similar to the <code>afterNextRender<\/code>, with the difference that instead of running the registered callback just once, it will run it after every single render, similar to <code>ngAfterContentChecked<\/code>. This could be used to read something from the DOM when it changes, such as the height of an element:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"767\" height=\"93\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/09\/image-19.png\" alt=\"\" class=\"wp-image-1461\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/09\/image-19.png 767w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/09\/image-19-300x36.png 300w\" sizes=\"auto, (max-width: 767px) 100vw, 767px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Angular keeps evolving at a steady pace, and Angular 16.2 brought a couple of interesting features to the table. The first feature is an addition to the Signals API that was part of a specific RFC for Signal-based components. The new feature consists of two functions: afterNextRender A function that allows registering a callback to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1459","post","type-post","status-publish","format-standard","hentry","category-angular"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=1459"}],"version-history":[{"count":2,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1459\/revisions"}],"predecessor-version":[{"id":1463,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1459\/revisions\/1463"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}