{"id":2228,"date":"2024-11-20T12:29:50","date_gmt":"2024-11-20T20:29:50","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=2228"},"modified":"2024-11-20T12:29:51","modified_gmt":"2024-11-20T20:29:51","slug":"whats-new-with-signals-in-angular-19","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/whats-new-with-signals-in-angular-19\/","title":{"rendered":"What&#8217;s new with Signals in Angular 19?"},"content":{"rendered":"\n<p>Angular 19 is now available with many different updates. A <a href=\"https:\/\/www.youtube.com\/watch?v=JvkX2_46gUY\" target=\"_blank\" rel=\"noopener\" title=\"\">video recap<\/a> (23 minutes long) of all these features is available on YouTube.<\/p>\n\n\n\n<p>There is a lot to unpack, so this week, my focus is on all signal-related updates.<\/p>\n\n\n\n<p>First, <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/whats-new-in-angular-17-1\/\" target=\"_blank\" rel=\"noopener\" title=\"\">signal-based input<\/a>, output, and <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/viewchild-and-contentchild-for-signal-based-queries\/\" target=\"_blank\" rel=\"noopener\" title=\"\">view query<\/a> functions are all stable APIs as of v19, which means you can use all of them safely. Here is the complete list of such stable features:<\/p>\n\n\n\n<p><code><a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/whats-new-in-angular-17-1\/\" target=\"_blank\" rel=\"noopener\" title=\"\">input()<\/a><\/code>,\u00a0<code>output()<\/code>,\u00a0<code><a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/model-for-signal-based-2-way-data-bindings\/\" target=\"_blank\" rel=\"noopener\" title=\"\">model()<\/a><\/code>,\u00a0<code>viewChild()<\/code>,\u00a0<code>viewChildren()<\/code>,\u00a0<code>contentChild<\/code>(),\u00a0<code>contentChildren()<\/code>,\u00a0<code><a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/angular-16-preview-takeuntildestroyed\/\" target=\"_blank\" rel=\"noopener\" title=\"\">takeUntilDestroyed()<\/a><\/code>,\u00a0<code>outputFromObservable()<\/code>, and\u00a0<code>outputToObservable()<\/code>\u00a0<\/p>\n\n\n\n<p>Yes, that&#8217;s a lot!<\/p>\n\n\n\n<p><strong>Second<\/strong>, to help you migrate your old <code>@Input()<\/code> and <code>@ViewChild()<\/code>to their signal-based equivalents, new Angular CLI migration commands are available:<\/p>\n\n\n\n<p><code>ng generate @angular\/core:signal-input-migration<br>ng generate @angular\/core:signal-queries-migration<br>ng generate @angular\/core:output-migration<\/code><\/p>\n\n\n\n<p>Initial feedback from these automated migrations is very positive.<\/p>\n\n\n\n<p><strong>The third update<\/strong>, a new type of Signal (in developer preview) called <code><a href=\"https:\/\/angular.dev\/guide\/signals\/linked-signal\" target=\"_blank\" rel=\"noopener\" title=\"\">linkedSignal<\/a><\/code>. This new function <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">also creates a\u00a0<a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/signals-computed\/\" target=\"_blank\" rel=\"noopener\">computed signal<\/a>\u00a0that can be written manually<\/span>. In other words, a <code>computed<\/code> signal is read-only, whereas a <code>linkedSignal<\/code> is writable while preserving automatic update and computation features of a <code>computed<\/code> signal.<\/p>\n\n\n\n<p><strong>The final and most significant update<\/strong> is the addition of a <a href=\"https:\/\/angular.dev\/guide\/signals\/resource\" target=\"_blank\" rel=\"noopener\" title=\"\">resource API<\/a> to Angular. This is a big one for several reasons: It enables total signal-based reactivity while using Promises or RxJs to fetch updates.<\/p>\n\n\n\n<p>Here is a code example:<\/p>\n\n\n\n<p><code>sortOrder = signal&lt;'asc' | 'desc'>('asc');<br>usersResource = rxResource({<br>     request: () => ({ sort: this.sortOrder() }),<br>     loader: ({ request }) => this.http.get('\/users', { params: { sort: request.sort } })<br>});<\/code><\/p>\n\n\n\n<p>The above code will send a request to <code>\/users<\/code> with the proper sort parameter every time the <code>sortOrder()<\/code> signal value changes. The result is an object with lots of information about the resource:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"466\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-20-at-2.11.20\u202fPM-1024x466.png\" alt=\"\" class=\"wp-image-2231\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-20-at-2.11.20\u202fPM-1024x466.png 1024w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-20-at-2.11.20\u202fPM-300x137.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-20-at-2.11.20\u202fPM-768x350.png 768w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-20-at-2.11.20\u202fPM.png 1454w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The approach is similar to <a href=\"https:\/\/blog.angulartraining.com\/how-to-create-signals-out-of-observables-26f952a9f0e4\" target=\"_blank\" rel=\"noopener\" title=\"\">ngx-signalify<\/a> or <a href=\"https:\/\/tanstack.com\/query\/latest\" target=\"_blank\" rel=\"noopener\" title=\"\">TanStack Query<\/a>, and it looks promising. Now, <code>resource<\/code> is in an experimental state, which means &#8220;do not use it in production yet&#8221; (the API will likely change), but you can l<a href=\"https:\/\/angular.dev\/guide\/signals\/resource\" target=\"_blank\" rel=\"noopener\" title=\"\">earn more about it here<\/a>. Because there&#8217;s so much more to it, I&#8217;ll write a dedicated post and\/or do a long-form video workshop on that topic.<\/p>\n\n\n\n<p>And that&#8217;s it for the four main updates regarding Signals in v19. I could add a fifth one with the <code>effect()<\/code> function still in developer preview but now allows writing other signals by default (no more need to add the option to perform such writes).<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Angular 19 is now available with many different updates. A video recap (23 minutes long) of all these features is available on YouTube. There is a lot to unpack, so this week, my focus is on all signal-related updates. First, signal-based input, output, and view query functions are all stable APIs as of v19, which [&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,29],"tags":[],"class_list":["post-2228","post","type-post","status-publish","format-standard","hentry","category-angular","category-signals"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/2228","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=2228"}],"version-history":[{"count":4,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/2228\/revisions"}],"predecessor-version":[{"id":2233,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/2228\/revisions\/2233"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=2228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=2228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=2228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}